Ticket #4454: transmission2.diff

File transmission2.diff, 6.5 KB (added by 0ptional, 9 years ago)
  • macosx/Torrent.h

     
    5252   
    5353    BOOL fResumeOnWake;
    5454   
    55     NSString * fTimeMachineExclude;
     55    BOOL fTimeMachineExcludeInitialized;
    5656}
    5757
    5858- (id) initWithPath: (NSString *) path location: (NSString *) location deleteTorrentFile: (BOOL) torrentDelete
  • macosx/Torrent.m

     
    3939        magnetAddress: (NSString *) magnetAddress lib: (tr_session *) lib
    4040        groupValue: (NSNumber *) groupValue
    4141        removeWhenFinishSeeding: (NSNumber *) removeWhenFinishSeeding
    42         timeMachineExcludeLocation: (NSString *) timeMachineExclude
    4342        downloadFolder: (NSString *) downloadFolder
    4443        legacyIncompleteFolder: (NSString *) incompleteFolder;
    4544
     
    5756- (BOOL) shouldShowEta;
    5857- (NSString *) etaString;
    5958
    60 - (void) setTimeMachineExclude: (BOOL) exclude forPath: (NSString *) path;
     59- (void) setTimeMachineExclude: (BOOL) exclude;
    6160
    6261@end
    6362
     
    112111    self = [self initWithPath: path hash: nil torrentStruct: NULL magnetAddress: nil lib: lib
    113112            groupValue: nil
    114113            removeWhenFinishSeeding: nil
    115             timeMachineExcludeLocation: nil
    116114            downloadFolder: location
    117115            legacyIncompleteFolder: nil];
    118116   
     
    129127    self = [self initWithPath: nil hash: nil torrentStruct: torrentStruct magnetAddress: nil lib: lib
    130128            groupValue: nil
    131129            removeWhenFinishSeeding: nil
    132             timeMachineExcludeLocation: nil
    133130            downloadFolder: location
    134131            legacyIncompleteFolder: nil];
    135132   
     
    141138    self = [self initWithPath: nil hash: nil torrentStruct: nil magnetAddress: address
    142139            lib: lib groupValue: nil
    143140            removeWhenFinishSeeding: nil
    144             timeMachineExcludeLocation: nil
    145141            downloadFolder: location legacyIncompleteFolder: nil];
    146142   
    147143    return self;
     
    156152                lib: lib
    157153                groupValue: [history objectForKey: @"GroupValue"]
    158154                removeWhenFinishSeeding: [history objectForKey: @"RemoveWhenFinishSeeding"]
    159                 timeMachineExcludeLocation: [history objectForKey: @"TimeMachineExcludeLocation"]
    160155                downloadFolder: [history objectForKey: @"DownloadFolder"] //upgrading from versions < 1.80
    161156                legacyIncompleteFolder: [[history objectForKey: @"UseIncompleteFolder"] boolValue] //upgrading from versions < 1.80
    162157                                        ? [history objectForKey: @"IncompleteFolder"] : nil];
     
    208203                                        [NSNumber numberWithInt: fGroupValue], @"GroupValue",
    209204                                        [NSNumber numberWithBool: fRemoveWhenFinishSeeding], @"RemoveWhenFinishSeeding", nil];
    210205   
    211     if (fTimeMachineExclude)
    212         [history setObject: fTimeMachineExclude forKey: @"TimeMachineExcludeLocation"];
    213    
    214206    return history;
    215207}
    216208
     
    231223    [fFileList release];
    232224    [fFlatFileList release];
    233225   
    234     [fTimeMachineExclude release];
    235    
    236226    [super dealloc];
    237227}
    238228
     
    249239- (void) closeRemoveTorrent: (BOOL) trashFiles
    250240{
    251241    //allow the file to be indexed by Time Machine
    252     if (fTimeMachineExclude)
    253     {
    254         [self setTimeMachineExclude: NO forPath: fTimeMachineExclude];
    255         [fTimeMachineExclude release];
    256         fTimeMachineExclude = nil;
    257     }
     242    [self setTimeMachineExclude: NO];
    258243   
    259244    tr_torrentRemove(fHandle, trashFiles, trashDataFile);
    260245}
    261246
    262247- (void) changeDownloadFolderBeforeUsing: (NSString *) folder
    263248{
    264      tr_torrentSetDownloadDir(fHandle, [folder UTF8String]);
    265      [self updateTimeMachineExclude];
     249    //if data existed in original download location,
     250    //unexclude it before changing the location
     251    [self setTimeMachineExclude: NO];
     252   
     253    tr_torrentSetDownloadDir(fHandle, [folder UTF8String]);
    266254}
    267255
    268256- (NSString *) currentDirectory
     
    309297    if (wasStalled != [self isStalled])
    310298        [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self];
    311299   
    312     //when the data first appears, update time machine exclusion
    313     if (!fTimeMachineExclude)
     300    //when the torrent is first loaded, update the time machine exclusion
     301    if (!fTimeMachineExcludeInitialized)
    314302        [self updateTimeMachineExclude];
    315303}
    316304
     
    15471535
    15481536- (void) updateTimeMachineExclude
    15491537{
    1550     NSString * currentLocation = ![self allDownloaded] ? [self dataLocation] : nil;
    1551    
    1552     //return if the locations are the same
    1553     if (fTimeMachineExclude && currentLocation && [fTimeMachineExclude isEqualToString: currentLocation])
    1554         return;
    1555    
    1556     //remove old location...
    1557     if (fTimeMachineExclude)
    1558     {
    1559         [self setTimeMachineExclude: NO forPath: fTimeMachineExclude];
    1560         [fTimeMachineExclude release];
    1561         fTimeMachineExclude = nil;
    1562     }
    1563    
    1564     //...set new location
    1565     if (currentLocation)
    1566     {
    1567         [self setTimeMachineExclude: YES forPath: currentLocation];
    1568         fTimeMachineExclude = [currentLocation retain];
    1569     }
     1538    [self setTimeMachineExclude: ![self allDownloaded]];
    15701539}
    15711540
    15721541- (NSInteger) stateSortKey
     
    16211590        magnetAddress: (NSString *) magnetAddress lib: (tr_session *) lib
    16221591        groupValue: (NSNumber *) groupValue
    16231592        removeWhenFinishSeeding: (NSNumber *) removeWhenFinishSeeding
    1624         timeMachineExcludeLocation: (NSString *) timeMachineExclude
    16251593        downloadFolder: (NSString *) downloadFolder
    16261594        legacyIncompleteFolder: (NSString *) incompleteFolder
    16271595{
     
    16891657    [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(checkGroupValueForRemoval:)
    16901658        name: @"GroupValueRemoved" object: nil];
    16911659   
    1692     fTimeMachineExclude = [timeMachineExclude retain];
     1660    fTimeMachineExcludeInitialized = NO;
    16931661    [self update];
    16941662   
    16951663    return self;
     
    19281896    return idleString;
    19291897}
    19301898
    1931 - (void) setTimeMachineExclude: (BOOL) exclude forPath: (NSString *) path
     1899- (void) setTimeMachineExclude: (BOOL) exclude
    19321900{
    1933     CSBackupSetItemExcluded((CFURLRef)[NSURL fileURLWithPath: path], exclude, true);
     1901    NSString * path;
     1902    if ((path = [self dataLocation]))
     1903    {
     1904        CSBackupSetItemExcluded((CFURLRef)[NSURL fileURLWithPath: path], exclude, false);
     1905        fTimeMachineExcludeInitialized = YES;
     1906    }
    19341907}
    19351908
    19361909@end