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
1=== modified file 'scoperegistry/FindFiles.cpp'
2--- scoperegistry/FindFiles.cpp 2014-11-25 04:35:11 +0000
3+++ scoperegistry/FindFiles.cpp 2015-01-20 06:21:41 +0000
4@@ -18,19 +18,13 @@
5
6 #include "FindFiles.h"
7
8-#include <unity/scopes/internal/safe_strerror.h>
9 #include <unity/UnityExceptions.h>
10-#include <unity/util/ResourcePtr.h>
11
12 #include <boost/algorithm/string.hpp>
13-#include <boost/filesystem/path.hpp>
14+#include <boost/filesystem.hpp>
15
16 #include <map>
17
18-#include <dirent.h>
19-#include <string.h>
20-#include <sys/stat.h>
21-
22 using namespace std;
23 using namespace unity;
24 using namespace boost;
25@@ -39,44 +33,38 @@
26 {
27
28 // Return all paths underneath the given dir that are of the given type
29-// or are a symbolic link.
30+// or are a symbolic link to the given type.
31
32 vector<string> find_entries(string const& install_dir, EntryType type)
33 {
34- DIR* d = opendir(install_dir.c_str());
35- if (d == NULL)
36- {
37- throw FileException("cannot open scope installation directory \"" + install_dir + "\": "
38- + scopes::internal::safe_strerror(errno),
39- errno);
40- }
41- util::ResourcePtr<DIR*, decltype(&closedir)> dir_ptr(d, closedir); // Clean up automatically
42-
43 vector<string> entries;
44
45- struct dirent* entry;
46- while ((entry = readdir(dir_ptr.get())) != NULL)
47- {
48- string name = entry->d_name;
49- if (name == "." || name == "..")
50- {
51- continue; // Ignore current and parent dir
52- }
53- struct stat st;
54- int rc = lstat((install_dir + "/" + name).c_str(), &st);
55- if (rc == -1)
56- {
57- continue; // We ignore errors, such as a file having been unlinked in the mean time.
58- }
59- if (type == File && !S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode))
60- {
61- continue; // Not a regular file or symbolic link
62- }
63- else if (type == Directory && !S_ISDIR(st.st_mode) && !S_ISLNK(st.st_mode))
64- {
65- continue; // Not a directory or symbolic link
66- }
67- entries.emplace_back(install_dir + "/" + name);
68+ if (!filesystem::is_directory(install_dir))
69+ {
70+ return entries;
71+ }
72+
73+ auto end_it = filesystem::directory_iterator();
74+ try
75+ {
76+ for (filesystem::directory_iterator dir_it(install_dir); dir_it != end_it; ++dir_it)
77+ {
78+ if (type == File && !filesystem::is_regular_file(*dir_it))
79+ {
80+ continue;
81+ }
82+ if (type == Directory && !filesystem::is_directory(*dir_it))
83+ {
84+ continue;
85+ }
86+ entries.emplace_back(install_dir + "/" + dir_it->path().filename().native());
87+ }
88+ }
89+ catch (std::exception const&)
90+ {
91+ // Ignore permission errors and the like.
92+ // If a scope installation directory lacks permission, we still get
93+ // get an error later, when we try to establish a watch for the install dir.
94 }
95
96 return entries;
97
98=== modified file 'scoperegistry/ScopesWatcher.cpp'
99--- scoperegistry/ScopesWatcher.cpp 2014-12-10 02:05:26 +0000
100+++ scoperegistry/ScopesWatcher.cpp 2015-01-20 06:21:41 +0000
101@@ -166,7 +166,10 @@
102 // Add a watch for this directory (ignore exception if already exists)
103 try
104 {
105- add_watch(dir);
106+ if (filesystem::is_directory(dir))
107+ {
108+ add_watch(dir); // Avoid noise if someone drops a file in here
109+ }
110 }
111 catch (unity::LogicException const&) {}
112

Subscribers

People subscribed via source and target branches

to all changes: