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
=== modified file 'src/daemon/scannerdaemon.cc'
--- src/daemon/scannerdaemon.cc 2014-09-30 11:50:44 +0000
+++ src/daemon/scannerdaemon.cc 2014-10-22 21:10:11 +0000
@@ -24,6 +24,8 @@
24#include<map>24#include<map>
25#include<memory>25#include<memory>
2626
27#include<sys/types.h>
28#include<sys/stat.h>
27#include<glib.h>29#include<glib.h>
28#include<glib-unix.h>30#include<glib-unix.h>
29#include<gio/gio.h>31#include<gio/gio.h>
@@ -42,6 +44,21 @@
4244
43using namespace mediascanner;45using namespace mediascanner;
4446
47namespace {
48
49bool is_same_directory(const char *dir1, const char *dir2) {
50 struct stat s1, s2;
51 if(stat(dir1, &s1) != 0) {
52 return false;
53 }
54 if(stat(dir2, &s2) != 0) {
55 return false;
56 }
57 return s1.st_dev == s2.st_dev && s1.st_ino == s2.st_ino;
58}
59
60}
61
45static const char BUS_NAME[] = "com.canonical.MediaScanner2.Daemon";62static const char BUS_NAME[] = "com.canonical.MediaScanner2.Daemon";
4663
47class ScannerDaemon final {64class ScannerDaemon final {
@@ -84,15 +101,20 @@
84 setupMountWatcher();101 setupMountWatcher();
85102
86 const char *musicdir = g_get_user_special_dir(G_USER_DIRECTORY_MUSIC);103 const char *musicdir = g_get_user_special_dir(G_USER_DIRECTORY_MUSIC);
87 if (musicdir)104 const char *videodir = g_get_user_special_dir(G_USER_DIRECTORY_VIDEOS);
105 const char *picturesdir = g_get_user_special_dir(G_USER_DIRECTORY_PICTURES);
106 const char *homedir = g_get_home_dir();
107
108 // According to XDG specification, when one of the special dirs is missing
109 // it falls back to home directory. This would mean scanning the entire home
110 // directory. This is probably not what people want so skip if this is the case.
111 if (musicdir && !is_same_directory(musicdir, homedir))
88 addDir(musicdir);112 addDir(musicdir);
89113
90 const char *videodir = g_get_user_special_dir(G_USER_DIRECTORY_VIDEOS);114 if (videodir && !is_same_directory(videodir, homedir))
91 if (videodir)
92 addDir(videodir);115 addDir(videodir);
93116
94 const char *picturesdir = g_get_user_special_dir(G_USER_DIRECTORY_PICTURES);117 if (picturesdir && !is_same_directory(picturesdir, homedir))
95 if (picturesdir)
96 addDir(picturesdir);118 addDir(picturesdir);
97119
98 // In case someone opened the db file before we could populate it.120 // In case someone opened the db file before we could populate it.

Subscribers

People subscribed via source and target branches