1 | /* |
---|
2 | * This file Copyright (C) 2008 Charles Kerr <charles@rebelbase.com> |
---|
3 | * |
---|
4 | * This file is licensed by the GPL version 2. Works owned by the |
---|
5 | * Transmission project are granted a special exemption to clause 2(b) |
---|
6 | * so that the bulk of its code can remain under the MIT license. |
---|
7 | * This exemption does not extend to derived works not owned by |
---|
8 | * the Transmission project. |
---|
9 | * |
---|
10 | * $Id:$ |
---|
11 | */ |
---|
12 | |
---|
13 | #include <string.h> |
---|
14 | #include <unistd.h> /* unlink */ |
---|
15 | |
---|
16 | #include "transmission.h" |
---|
17 | #include "fastresume.h" |
---|
18 | #include "platform.h" /* tr_getResumeDir */ |
---|
19 | #include "resume.h" |
---|
20 | #include "torrent.h" |
---|
21 | #include "utils.h" /* tr_buildPath */ |
---|
22 | |
---|
23 | static void |
---|
24 | getResumeFilename( char * buf, size_t buflen, const tr_torrent * tor ) |
---|
25 | { |
---|
26 | const char * dir = tr_getResumeDir( tor->handle ); |
---|
27 | char base[4096]; |
---|
28 | snprintf( base, sizeof( base ), "%s.%10.10s.resume", tor->info.name, tor->info.hashString ); |
---|
29 | tr_buildPath( buf, buflen, dir, base, NULL ); |
---|
30 | fprintf( stderr, "filename is [%s]\n", buf ); |
---|
31 | } |
---|
32 | |
---|
33 | uint64_t |
---|
34 | tr_torrentLoadResume( tr_torrent * tor, |
---|
35 | uint64_t fieldsToLoad, |
---|
36 | const tr_ctor * ctor ) |
---|
37 | { |
---|
38 | uint64_t fieldsLoaded = 0; |
---|
39 | uint8_t * content; |
---|
40 | size_t contentLen; |
---|
41 | char filename[MAX_PATH_LENGTH]; |
---|
42 | |
---|
43 | getResumeFilename( filename, sizeof( filename ), tor ); |
---|
44 | content = tr_loadFile( filename, &contentLen ); |
---|
45 | if( content ) |
---|
46 | { |
---|
47 | tr_free( content ); |
---|
48 | } |
---|
49 | else |
---|
50 | { |
---|
51 | fieldsLoaded = tr_fastResumeLoad( tor, fieldsToLoad, ctor ); |
---|
52 | } |
---|
53 | |
---|
54 | return fieldsLoaded; |
---|
55 | } |
---|
56 | |
---|
57 | void |
---|
58 | tr_torrentSaveResume( const tr_torrent * tor ) |
---|
59 | { |
---|
60 | char filename[MAX_PATH_LENGTH]; |
---|
61 | getResumeFilename( filename, sizeof( filename ), tor ); |
---|
62 | |
---|
63 | /* (temporary) */ |
---|
64 | tr_fastResumeSave( tor ); |
---|
65 | } |
---|
66 | |
---|
67 | void |
---|
68 | tr_torrentRemoveResume( const tr_torrent * tor ) |
---|
69 | { |
---|
70 | char filename[MAX_PATH_LENGTH]; |
---|
71 | getResumeFilename( filename, sizeof( filename ), tor ); |
---|
72 | unlink( filename ); |
---|
73 | tr_fastResumeRemove( tor ); |
---|
74 | } |
---|