Merge lp:~michihenning/unity-scopes-api/registry-noise into lp:unity-scopes-api

Proposed by Michi Henning
Status: Merged
Approved by: Paweł Stołowski
Approved revision: 281
Merged at revision: 297
Proposed branch: lp:~michihenning/unity-scopes-api/registry-noise
Merge into: lp:unity-scopes-api
Diff against target: 111 lines (+32/-41)
2 files modified
scoperegistry/FindFiles.cpp (+28/-40)
scoperegistry/ScopesWatcher.cpp (+4/-1)
To merge this branch: bzr merge lp:~michihenning/unity-scopes-api/registry-noise
Reviewer Review Type Date Requested Status
Paweł Stołowski (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+246976@code.launchpad.net

Commit message

Removed a bunch of noise that was logged by the registry if the scope installation dirs contained unexpected files or files without permission.

Simplified FindFiles.cpp by using boost::filesystem instead of dirent.

Description of the change

Removed a bunch of noise that was logged by the registry if the scope installation dirs contained unexpected files or files without permission.

Simplified FindFiles.cpp by using boost::filesystem instead of dirent.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Paweł Stołowski (stolowski) wrote :

Looks good. We need to make sure it doesn't cause any regression with broken click scopes (such as sbbscope - swiss transport scope). +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'scoperegistry/FindFiles.cpp'
--- scoperegistry/FindFiles.cpp 2014-11-25 04:35:11 +0000
+++ scoperegistry/FindFiles.cpp 2015-01-20 06:21:41 +0000
@@ -18,19 +18,13 @@
1818
19#include "FindFiles.h"19#include "FindFiles.h"
2020
21#include <unity/scopes/internal/safe_strerror.h>
22#include <unity/UnityExceptions.h>21#include <unity/UnityExceptions.h>
23#include <unity/util/ResourcePtr.h>
2422
25#include <boost/algorithm/string.hpp>23#include <boost/algorithm/string.hpp>
26#include <boost/filesystem/path.hpp>24#include <boost/filesystem.hpp>
2725
28#include <map>26#include <map>
2927
30#include <dirent.h>
31#include <string.h>
32#include <sys/stat.h>
33
34using namespace std;28using namespace std;
35using namespace unity;29using namespace unity;
36using namespace boost;30using namespace boost;
@@ -39,44 +33,38 @@
39{33{
4034
41// Return all paths underneath the given dir that are of the given type35// Return all paths underneath the given dir that are of the given type
42// or are a symbolic link.36// or are a symbolic link to the given type.
4337
44vector<string> find_entries(string const& install_dir, EntryType type)38vector<string> find_entries(string const& install_dir, EntryType type)
45{39{
46 DIR* d = opendir(install_dir.c_str());
47 if (d == NULL)
48 {
49 throw FileException("cannot open scope installation directory \"" + install_dir + "\": "
50 + scopes::internal::safe_strerror(errno),
51 errno);
52 }
53 util::ResourcePtr<DIR*, decltype(&closedir)> dir_ptr(d, closedir); // Clean up automatically
54
55 vector<string> entries;40 vector<string> entries;
5641
57 struct dirent* entry;42 if (!filesystem::is_directory(install_dir))
58 while ((entry = readdir(dir_ptr.get())) != NULL)43 {
59 {44 return entries;
60 string name = entry->d_name;45 }
61 if (name == "." || name == "..")46
62 {47 auto end_it = filesystem::directory_iterator();
63 continue; // Ignore current and parent dir48 try
64 }49 {
65 struct stat st;50 for (filesystem::directory_iterator dir_it(install_dir); dir_it != end_it; ++dir_it)
66 int rc = lstat((install_dir + "/" + name).c_str(), &st);51 {
67 if (rc == -1)52 if (type == File && !filesystem::is_regular_file(*dir_it))
68 {53 {
69 continue; // We ignore errors, such as a file having been unlinked in the mean time.54 continue;
70 }55 }
71 if (type == File && !S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode))56 if (type == Directory && !filesystem::is_directory(*dir_it))
72 {57 {
73 continue; // Not a regular file or symbolic link58 continue;
74 }59 }
75 else if (type == Directory && !S_ISDIR(st.st_mode) && !S_ISLNK(st.st_mode))60 entries.emplace_back(install_dir + "/" + dir_it->path().filename().native());
76 {61 }
77 continue; // Not a directory or symbolic link62 }
78 }63 catch (std::exception const&)
79 entries.emplace_back(install_dir + "/" + name);64 {
65 // Ignore permission errors and the like.
66 // If a scope installation directory lacks permission, we still get
67 // get an error later, when we try to establish a watch for the install dir.
80 }68 }
8169
82 return entries;70 return entries;
8371
=== modified file 'scoperegistry/ScopesWatcher.cpp'
--- scoperegistry/ScopesWatcher.cpp 2014-12-10 02:05:26 +0000
+++ scoperegistry/ScopesWatcher.cpp 2015-01-20 06:21:41 +0000
@@ -166,7 +166,10 @@
166 // Add a watch for this directory (ignore exception if already exists)166 // Add a watch for this directory (ignore exception if already exists)
167 try167 try
168 {168 {
169 add_watch(dir);169 if (filesystem::is_directory(dir))
170 {
171 add_watch(dir); // Avoid noise if someone drops a file in here
172 }
170 }173 }
171 catch (unity::LogicException const&) {}174 catch (unity::LogicException const&) {}
172175

Subscribers

People subscribed via source and target branches

to all changes: