Merge lp:~jpakkane/mediascanner2/skipspecialhome into lp:mediascanner2

Proposed by Jussi Pakkanen
Status: Merged
Approved by: James Henstridge
Approved revision: 287
Merged at revision: 293
Proposed branch: lp:~jpakkane/mediascanner2/skipspecialhome
Merge into: lp:mediascanner2
Diff against target: 60 lines (+27/-5)
1 file modified
src/daemon/scannerdaemon.cc (+27/-5)
To merge this branch: bzr merge lp:~jpakkane/mediascanner2/skipspecialhome
Reviewer Review Type Date Requested Status
James Henstridge Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+239312@code.launchpad.net

Commit message

Skip scanning of special directories if they point to user home dir.

Description of the change

Skip scanning of special directories if they point to user home dir.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
James Henstridge (jamesh) :
Revision history for this message
James Henstridge (jamesh) wrote :

Ignore my previous question. I had lstat/stat mixed up.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/daemon/scannerdaemon.cc'
2--- src/daemon/scannerdaemon.cc 2014-09-30 11:50:44 +0000
3+++ src/daemon/scannerdaemon.cc 2014-10-22 21:10:11 +0000
4@@ -24,6 +24,8 @@
5 #include<map>
6 #include<memory>
7
8+#include<sys/types.h>
9+#include<sys/stat.h>
10 #include<glib.h>
11 #include<glib-unix.h>
12 #include<gio/gio.h>
13@@ -42,6 +44,21 @@
14
15 using namespace mediascanner;
16
17+namespace {
18+
19+bool is_same_directory(const char *dir1, const char *dir2) {
20+ struct stat s1, s2;
21+ if(stat(dir1, &s1) != 0) {
22+ return false;
23+ }
24+ if(stat(dir2, &s2) != 0) {
25+ return false;
26+ }
27+ return s1.st_dev == s2.st_dev && s1.st_ino == s2.st_ino;
28+}
29+
30+}
31+
32 static const char BUS_NAME[] = "com.canonical.MediaScanner2.Daemon";
33
34 class ScannerDaemon final {
35@@ -84,15 +101,20 @@
36 setupMountWatcher();
37
38 const char *musicdir = g_get_user_special_dir(G_USER_DIRECTORY_MUSIC);
39- if (musicdir)
40+ const char *videodir = g_get_user_special_dir(G_USER_DIRECTORY_VIDEOS);
41+ const char *picturesdir = g_get_user_special_dir(G_USER_DIRECTORY_PICTURES);
42+ const char *homedir = g_get_home_dir();
43+
44+ // According to XDG specification, when one of the special dirs is missing
45+ // it falls back to home directory. This would mean scanning the entire home
46+ // directory. This is probably not what people want so skip if this is the case.
47+ if (musicdir && !is_same_directory(musicdir, homedir))
48 addDir(musicdir);
49
50- const char *videodir = g_get_user_special_dir(G_USER_DIRECTORY_VIDEOS);
51- if (videodir)
52+ if (videodir && !is_same_directory(videodir, homedir))
53 addDir(videodir);
54
55- const char *picturesdir = g_get_user_special_dir(G_USER_DIRECTORY_PICTURES);
56- if (picturesdir)
57+ if (picturesdir && !is_same_directory(picturesdir, homedir))
58 addDir(picturesdir);
59
60 // In case someone opened the db file before we could populate it.

Subscribers

People subscribed via source and target branches