Skip to content

Commit

Permalink
implement DeleteSourceAfterBackup
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaskueffel committed Sep 8, 2023
1 parent 36c72f9 commit e446f94
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions FileSyncJob/FileSyncJobOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class FileSyncJobOptions : IFileSyncJobOptions
public List<string> Subfolders { get; set; }
public bool Recursive { get; set; } = true;
public bool SyncDeleted { get; set; } = false;
public bool DeleteSourceAfterBackup { get; set; } = false;
public FileSyncProvider FileSyncProvider { get; set; } = FileSyncProvider.FileIO;

public FileSyncJobOptions()
Expand Down
6 changes: 6 additions & 0 deletions FileSyncJob/FileSyncJobOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public IFileSyncJobOptionsBuilderSetProperties WithSubfolder(string subfolder)
jobOptions.Subfolders.Add(subfolder);
return this;
}
public IFileSyncJobOptionsBuilderSetProperties DeleteAfterBackup(bool deleteAfterBackup)
{
jobOptions.DeleteSourceAfterBackup = deleteAfterBackup;
return this;
}
public IFileSyncJobOptionsBuilderSetProperties WithInterval(TimeSpan interval)
{
jobOptions.Interval = interval;
Expand Down Expand Up @@ -124,6 +129,7 @@ public interface IFileSyncJobOptionsBuilderSetProperties : IFileSyncJobOptionsBu
IFileSyncJobOptionsBuilderSetProperties WithCredentials(NetworkCredential networkCredential);
IFileSyncJobOptionsBuilderSetProperties WithSearchPattern(string searchPattern);
IFileSyncJobOptionsBuilderSetProperties WithSubfolder(string subfolder);
IFileSyncJobOptionsBuilderSetProperties DeleteAfterBackup(bool deleteAfterBackup);
IFileSyncJobOptionsBuilderSetProperties WithLogger(ILogger logger);
IFileSyncJobOptionsBuilderSetProperties WithLogger(Action<string> loggerAction);
}
Expand Down
1 change: 1 addition & 0 deletions FileSyncJob/IFileSyncJobOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface IFileSyncJobOptions
string SearchPattern { get; set; }
List<string> Subfolders { get; set; }
string SourcePath { get; set; }
bool DeleteSourceAfterBackup { get; set; }
bool SyncDeleted { get; set; }
}
}
4 changes: 4 additions & 0 deletions SyncProviders/FileIOProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public override void SyncSourceToDest()
logger.LogDebug("Copy {A}", relativeFilename);
File.Copy(f.FullName, remotefile.FullName, true);
copied++;
if (JobOptions.DeleteSourceAfterBackup)
{
File.Delete(f.FullName);
}
}
catch (Exception exc)
{
Expand Down
4 changes: 4 additions & 0 deletions SyncProviders/SmbLibProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ public override void SyncSourceToDest()
try
{
WriteFile(f.FullName, remotefile);
if (JobOptions.DeleteSourceAfterBackup)
{
File.Delete(f.FullName);
}
}
catch (Exception exc)
{
Expand Down

0 comments on commit e446f94

Please sign in to comment.