Merge lp:~jamesh/mediascanner/mediastore-path into lp:mediascanner/v2

Proposed by James Henstridge
Status: Merged
Approved by: James Henstridge
Approved revision: 188
Merged at revision: 186
Proposed branch: lp:~jamesh/mediascanner/mediastore-path
Merge into: lp:mediascanner/v2
Diff against target: 185 lines (+60/-41)
4 files modified
src/daemon/scannerdaemon.cc (+20/-30)
src/mediascanner/MediaStore.cc (+33/-4)
src/mediascanner/MediaStore.hh (+1/-0)
src/utils/query.cc (+6/-7)
To merge this branch: bzr merge lp:~jamesh/mediascanner/mediastore-path
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Mediascanner Team Pending
Review via email: mp+196265@code.launchpad.net

Commit message

Add a constructor for MediaStore that opens the default database. This removes the need for users of the client locate the library themselves.

Description of the change

Add a constructor for MediaStore that opens the default database. This removes the need for users of the client locate the library themselves.

To post a comment you must log in.
188. By James Henstridge

Update the query test program to open the default database. The
MEDIASCANNER_CACHE environment variable can be used to point it at
different databases.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

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 2013-11-12 05:00:59 +0000
3+++ src/daemon/scannerdaemon.cc 2013-11-22 11:59:26 +0000
4@@ -17,24 +17,26 @@
5 * along with this program. If not, see <http://www.gnu.org/licenses/>.
6 */
7
8-#include "../mediascanner/MediaFile.hh"
9-#include "../mediascanner/MediaStore.hh"
10-#include "MetadataExtractor.hh"
11-#include "SubtreeWatcher.hh"
12-#include "Scanner.hh"
13-
14-#include<cstdio>
15-#include<gst/gst.h>
16 #include<sys/select.h>
17 #include<sys/stat.h>
18 #include<sys/inotify.h>
19+#include<unistd.h>
20+#include<cstdio>
21 #include<cerrno>
22 #include<cstring>
23-#include<unistd.h>
24 #include<map>
25 #include<memory>
26 #include<cassert>
27
28+#include<glib.h>
29+#include<gst/gst.h>
30+
31+#include "../mediascanner/MediaFile.hh"
32+#include "../mediascanner/MediaStore.hh"
33+#include "MetadataExtractor.hh"
34+#include "SubtreeWatcher.hh"
35+#include "Scanner.hh"
36+
37 using namespace std;
38
39 class ScannerDaemon final {
40@@ -61,32 +63,20 @@
41 };
42
43 ScannerDaemon::ScannerDaemon() {
44- string homedir = "/home/";
45- homedir += getlogin();
46- string musicdir = homedir + "/Music";
47- string videodir = homedir + "/Videos";
48- char *env_cachedir = getenv("MEDIASCANNER_CACHEDIR");
49- if(env_cachedir) {
50- cachedir = env_cachedir;
51- } else {
52- cachedir = homedir + "/.cache/mediascanner-test";
53- }
54- int ec;
55- errno = 0;
56- ec = mkdir(cachedir.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
57- if(ec < 0 && errno != EEXIST) {
58- string msg("Could not create cache dir: ");
59- msg += strerror(errno);
60- throw runtime_error(msg);
61- }
62 mountDir = string("/media/") + getlogin();
63- unique_ptr<MediaStore> tmp(new MediaStore(cachedir + "/mediastore.db", MS_READ_WRITE, "/media/"));
64+ unique_ptr<MediaStore> tmp(new MediaStore(MS_READ_WRITE, "/media/"));
65 store = move(tmp);
66 extractor.reset(new MetadataExtractor());
67 setupMountWatcher();
68 addMountedVolumes();
69- addDir(musicdir);
70- addDir(videodir);
71+
72+ const char *musicdir = g_get_user_special_dir(G_USER_DIRECTORY_MUSIC);
73+ if (musicdir)
74+ addDir(musicdir);
75+
76+ const char *videodir = g_get_user_special_dir(G_USER_DIRECTORY_VIDEOS);
77+ if (videodir)
78+ addDir(videodir);
79 }
80
81 ScannerDaemon::~ScannerDaemon() {
82
83=== modified file 'src/mediascanner/MediaStore.cc'
84--- src/mediascanner/MediaStore.cc 2013-11-20 11:36:25 +0000
85+++ src/mediascanner/MediaStore.cc 2013-11-22 11:59:26 +0000
86@@ -17,16 +17,22 @@
87 * along with this program. If not, see <http://www.gnu.org/licenses/>.
88 */
89
90+#include <sys/stat.h>
91+#include <unistd.h>
92+#include <cerrno>
93+#include <cstdint>
94+#include <cstring>
95+#include <stdexcept>
96+
97+#include <glib.h>
98+#include <sqlite3.h>
99+
100 #include "mozilla/fts3_tokenizer.h"
101 #include"MediaStore.hh"
102 #include"MediaFile.hh"
103 #include "Album.hh"
104 #include "sqliteutils.hh"
105 #include"utils.hh"
106-#include <sqlite3.h>
107-#include <cstdint>
108-#include <cstdio>
109-#include <stdexcept>
110
111 using namespace std;
112
113@@ -194,6 +200,29 @@
114 version.step();
115 }
116
117+static std::string get_default_database() {
118+ std::string cachedir;
119+
120+ char *env_cachedir = getenv("MEDIASCANNER_CACHEDIR");
121+ if (env_cachedir) {
122+ cachedir = env_cachedir;
123+ } else {
124+ cachedir = g_get_user_cache_dir();
125+ cachedir += "/mediascanner-test";
126+ }
127+ if (g_mkdir_with_parents(cachedir.c_str(), S_IRWXU) < 0) {
128+ std::string msg("Could not create cache dir: ");
129+ msg += strerror(errno);
130+ throw runtime_error(msg);
131+ }
132+ return cachedir + "/mediastore.db";
133+}
134+
135+MediaStore::MediaStore(OpenType access, const std::string &retireprefix)
136+ : MediaStore(get_default_database(), access, retireprefix)
137+{
138+}
139+
140 MediaStore::MediaStore(const std::string &filename, OpenType access, const std::string &retireprefix) {
141 int sqliteFlags = access == MS_READ_WRITE ? SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE : SQLITE_OPEN_READONLY;
142 p = new MediaStorePrivate();
143
144=== modified file 'src/mediascanner/MediaStore.hh'
145--- src/mediascanner/MediaStore.hh 2013-11-12 04:35:16 +0000
146+++ src/mediascanner/MediaStore.hh 2013-11-22 11:59:26 +0000
147@@ -38,6 +38,7 @@
148 MediaStorePrivate *p;
149
150 public:
151+ MediaStore(OpenType access, const std::string &retireprefix="");
152 MediaStore(const std::string &filename, OpenType access, const std::string &retireprefix="");
153 MediaStore(const MediaStore &other) = delete;
154 MediaStore operator=(const MediaStore &other) = delete;
155
156=== modified file 'src/utils/query.cc'
157--- src/utils/query.cc 2013-11-13 07:19:59 +0000
158+++ src/utils/query.cc 2013-11-22 11:59:26 +0000
159@@ -27,8 +27,8 @@
160
161 using namespace std;
162
163-void queryDb(const string &db_file, const string &core_term) {
164- MediaStore store(db_file, MS_READ_ONLY);
165+void queryDb(const string &core_term) {
166+ MediaStore store(MS_READ_ONLY);
167 vector<MediaFile> results;
168 results = store.query(core_term, AudioMedia);
169 if(results.empty()) {
170@@ -52,11 +52,10 @@
171 }
172
173 int main(int argc, char **argv) {
174- if(argc < 3) {
175- printf("%s <db file> <term>\n", argv[0]);
176+ if(argc < 2) {
177+ printf("%s <term>\n", argv[0]);
178 return 1;
179 }
180- string db_file(argv[1]);
181- string core_term(argv[2]);
182- queryDb(db_file, core_term);
183+ string core_term(argv[1]);
184+ queryDb(core_term);
185 }

Subscribers

People subscribed via source and target branches