~ci-train-bot/thumbnailer/latestsnapshot-ubuntu-recup

« back to all changes in this revision

Viewing changes to src/thumbnailcache.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Jussi Pakkanen, Ubuntu daily release
  • Date: 2013-10-03 03:26:49 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20131003032649-dh4ryu2x1ng6zkve
Tags: 1.0+13.10.20131003-0ubuntu1
[ Jussi Pakkanen ]
* Run gstreamer video pipelines in an external process.
* Get helper path from config.h.
* Use helper binary from build dir when running tests.
* Adds support for full resolution thumbnails.

[ Ubuntu daily release ]
* Automatic snapshot from revision 48

Show diffs side-by-side

added added

removed removed

Lines of Context:
126
126
    string tndir;
127
127
    string smalldir;
128
128
    string largedir;
 
129
    string originaldir;
129
130
    static const size_t MAX_FILES = 200;
130
131
 
131
132
};
133
134
void ThumbnailCachePrivate::clear() {
134
135
    cleardir(smalldir);
135
136
    cleardir(largedir);
 
137
    cleardir(originaldir);
136
138
}
137
139
 
138
140
 
139
141
void ThumbnailCachePrivate::prune() {
140
142
    prune_dir(smalldir, MAX_FILES);
141
143
    prune_dir(largedir, MAX_FILES);
 
144
    prune_dir(originaldir, MAX_FILES);
142
145
}
143
146
 
144
147
void ThumbnailCachePrivate::delete_from_cache(const std::string &abs_path) {
145
148
    unlink(get_cache_file_name(abs_path, TN_SIZE_SMALL).c_str());
146
149
    unlink(get_cache_file_name(abs_path, TN_SIZE_LARGE).c_str());
 
150
    unlink(get_cache_file_name(abs_path, TN_SIZE_ORIGINAL).c_str());
 
151
}
147
152
 
 
153
static string makedir(const string &base, const string &subdir) {
 
154
    string dirname = base;
 
155
    dirname += "/";
 
156
    dirname += subdir;
 
157
    int ec;
 
158
    errno = 0;
 
159
    ec = mkdir(dirname.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
 
160
    if (ec < 0 && errno != EEXIST) {
 
161
        string s("Could not create ");
 
162
        s += subdir;
 
163
        s += " - ";
 
164
        s += strerror(errno);
 
165
        throw runtime_error(s);
 
166
    }
 
167
    return dirname;
148
168
}
149
169
 
150
170
ThumbnailCachePrivate::ThumbnailCachePrivate() {
180
200
    }
181
201
    if(!use_global) {
182
202
        string app_pkgname = get_app_pkg_name();
183
 
        xdg_base += "/" + app_pkgname;
184
 
        errno = 0;
185
 
        ec = mkdir(xdg_base.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
186
 
        if (ec < 0 && errno != EEXIST) {
187
 
            string s("Could not create app local dir ");
188
 
            s += xdg_base;
189
 
            s += " - ";
190
 
            s += strerror(errno);
191
 
            throw runtime_error(s);
192
 
        }
 
203
        xdg_base  = makedir(xdg_base, app_pkgname);
193
204
    }
194
205
    tndir = xdg_base + "/thumbnails";
195
 
    ec = mkdir(tndir.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
196
 
    if (ec < 0 && errno != EEXIST) {
197
 
        string s("Could not create thumbnail dir - ");
198
 
        s += strerror(errno);
199
 
        throw runtime_error(s);
200
 
    }
201
 
    smalldir = tndir + "/normal";
202
 
    ec = mkdir(smalldir.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
203
 
    if (ec < 0 && errno != EEXIST) {
204
 
        string s("Could not create small dir - ");
205
 
        s += strerror(errno);
206
 
        throw runtime_error(s);
207
 
    }
208
 
    largedir = tndir + "/large";
209
 
    ec = mkdir(largedir.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
210
 
    if (ec < 0 && errno != EEXIST) {
211
 
        string s("Could not create large dir - ");
212
 
        s += strerror(errno);
213
 
        throw runtime_error(s);
214
 
    }
 
206
    tndir = makedir(xdg_base, "thumbnails");
 
207
    smalldir = makedir(tndir,"normal");
 
208
    largedir = makedir(tndir, "large");;
 
209
    originaldir = makedir(tndir, "original");
215
210
}
216
211
 
217
212
string ThumbnailCachePrivate::md5(const string &str) const {
234
229
 
235
230
string ThumbnailCachePrivate::get_cache_file_name(const std::string & abs_original, ThumbnailSize desired) const {
236
231
    assert(abs_original[0] == '/');
237
 
    string path = desired == TN_SIZE_SMALL ? smalldir : largedir;
 
232
    string path;
 
233
    switch(desired) {
 
234
    case TN_SIZE_SMALL : path = smalldir; break;
 
235
    case TN_SIZE_LARGE : path = largedir; break;
 
236
    case TN_SIZE_ORIGINAL : path = originaldir; break;
 
237
    default : throw runtime_error("Unreachable code");
 
238
    }
238
239
    path += "/" + md5("file://" + abs_original) + ".png";
239
240
    return path;
240
241
}