~unity-api-team/thumbnailer/trusty

« back to all changes in this revision

Viewing changes to src/thumbnailcache.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-02-18 23:01:31 UTC
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: package-import@ubuntu.com-20140218230131-8bxr5ucdqo8wums2
Tags: upstream-1.0+14.04.20140218
ImportĀ upstreamĀ versionĀ 1.0+14.04.20140218

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17
17
 */
18
18
 
 
19
#ifndef _POSIX_SOURCE
 
20
#define _POSIX_SOURCE
 
21
#endif
 
22
 
19
23
#include<thumbnailer.h>
20
24
#include<internal/thumbnailcache.h>
21
25
#include<stdexcept>
22
26
#include<glib.h>
23
27
#include<sys/stat.h>
 
28
#include<sys/types.h>
24
29
#include<cassert>
25
30
#include<cstdio>
26
31
#include<cstring>
29
34
#include<unistd.h>
30
35
#include<vector>
31
36
#include<algorithm>
 
37
#include<dirent.h>
32
38
 
33
39
using namespace std;
34
40
 
212
218
string ThumbnailCachePrivate::md5(const string &str) const {
213
219
    const unsigned char *buf = (const unsigned char *)str.c_str();
214
220
    char *normalized = g_utf8_normalize((const gchar*)buf, str.size(), G_NORMALIZE_ALL);
215
 
    string final;
 
221
    string final_result;
216
222
    gchar *result;
217
223
 
218
224
    if(normalized) {
221
227
    gssize bytes = str.length();
222
228
 
223
229
    result = g_compute_checksum_for_data(G_CHECKSUM_MD5, buf, bytes);
224
 
    final = result;
 
230
    final_result = result;
225
231
    g_free((gpointer)normalized);
226
232
    g_free(result);
227
 
    return final;
 
233
    return final_result;
228
234
}
229
235
 
230
236
string ThumbnailCachePrivate::get_cache_file_name(const std::string & abs_original, ThumbnailSize desired) const {
262
268
        existed = true;
263
269
        fclose(f);
264
270
    }
 
271
    // Has it been changed since the thumbnail was taken?
 
272
    if(existed) {
 
273
        struct stat original, thumbnail;
 
274
        stat(abs_path.c_str(), &original);
 
275
        stat(fname.c_str(), &thumbnail);
 
276
        if(original.st_mtime > thumbnail.st_mtime) {
 
277
            p->delete_from_cache(abs_path);
 
278
            return "";
 
279
        }
 
280
    }
265
281
    return existed ? fname : string("");
266
282
}
267
283