mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-15 20:26:53 +02:00
* Implement #763 - Delete local files after sync
This commit is contained in:
parent
8c7f664199
commit
f2fe718389
1
config
1
config
|
@ -32,3 +32,4 @@
|
|||
# sync_root_files = "false"
|
||||
# classify_as_big_delete = "1000"
|
||||
# user_agent = ""
|
||||
# remove_source_files = "false"
|
|
@ -64,6 +64,8 @@ final class Config
|
|||
longValues["monitor_fullscan_frequency"] = 10;
|
||||
// Number of children in a path that is locally removed which will be classified as a 'big data delete'
|
||||
longValues["classify_as_big_delete"] = 1000;
|
||||
// Delete source after successful transfer
|
||||
boolValues["remove_source_files"] = false;
|
||||
|
||||
// Determine the users home directory.
|
||||
// Need to avoid using ~ here as expandTilde() below does not interpret correctly when running under init.d or systemd scripts
|
||||
|
@ -166,6 +168,7 @@ final class Config
|
|||
boolValues["monitor"] = false;
|
||||
boolValues["synchronize"] = false;
|
||||
boolValues["force"] = false;
|
||||
boolValues["remove_source_files"] = false;
|
||||
|
||||
// Application Startup option validation
|
||||
try {
|
||||
|
@ -269,6 +272,9 @@ final class Config
|
|||
"remove-directory",
|
||||
"Remove a directory on OneDrive - no sync will be performed.",
|
||||
&stringValues["remove_directory"],
|
||||
"remove-source-files",
|
||||
"Remove source file after successful transfer to OneDrive when using --upload-only",
|
||||
&boolValues["remove_source_files"],
|
||||
"single-directory",
|
||||
"Specify a single local directory within the OneDrive root to sync.",
|
||||
&stringValues["single_directory"],
|
||||
|
@ -444,7 +450,7 @@ void outputLongHelp(Option[] opt)
|
|||
"--skip-file",
|
||||
"--source-directory",
|
||||
"--syncdir",
|
||||
"--user-agent" ];
|
||||
"--user-agent" ];
|
||||
writeln(`OneDrive - a client for OneDrive Cloud Services
|
||||
|
||||
Usage:
|
||||
|
@ -478,4 +484,3 @@ unittest
|
|||
cfg.load("config");
|
||||
assert(cfg.getValueString("sync_dir") == "~/OneDrive");
|
||||
}
|
||||
|
||||
|
|
20
src/main.d
20
src/main.d
|
@ -274,7 +274,7 @@ int main(string[] args)
|
|||
|
||||
// Are we able to reach the OneDrive Service
|
||||
bool online = false;
|
||||
|
||||
|
||||
// dry-run database setup
|
||||
if (cfg.getValueBool("dry_run")) {
|
||||
// Make a copy of the original items.sqlite3 for use as the dry run copy if it exists
|
||||
|
@ -544,9 +544,21 @@ int main(string[] args)
|
|||
}
|
||||
}
|
||||
|
||||
// We should only set noRemoteDelete in an upload-only scenario
|
||||
if ((cfg.getValueBool("upload_only"))&&(cfg.getValueBool("no_remote_delete"))) sync.setNoRemoteDelete();
|
||||
|
||||
// Do we need to configure specific --upload-only options?
|
||||
if (cfg.getValueBool("upload_only")) {
|
||||
// --upload-only was passed in or configured
|
||||
// was --no-remote-delete passed in or configured
|
||||
if (cfg.getValueBool("no_remote_delete")) {
|
||||
// Configure the noRemoteDelete flag
|
||||
sync.setNoRemoteDelete();
|
||||
}
|
||||
// was --remove-source-files passed in or configured
|
||||
if (cfg.getValueBool("remove_source_files")) {
|
||||
// Configure the localDeleteAfterUpload flag
|
||||
sync.setLocalDeleteAfterUpload();
|
||||
}
|
||||
}
|
||||
|
||||
// Do we configure to disable the upload validation routine
|
||||
if (cfg.getValueBool("disable_upload_validation")) sync.setDisableUploadValidation();
|
||||
|
||||
|
|
43
src/sync.d
43
src/sync.d
|
@ -15,9 +15,12 @@ static import log;
|
|||
// threshold after which files will be uploaded using an upload session
|
||||
private long thresholdFileSize = 4 * 2^^20; // 4 MiB
|
||||
|
||||
// flag to set whether local files should be deleted
|
||||
// flag to set whether local files should be deleted from OneDrive
|
||||
private bool noRemoteDelete = false;
|
||||
|
||||
// flag to set whether the local file should be deleted once it is successfully uploaded to OneDrive
|
||||
private bool localDeleteAfterUpload = false;
|
||||
|
||||
// flag to set if we are running as uploadOnly
|
||||
private bool uploadOnly = false;
|
||||
|
||||
|
@ -378,6 +381,13 @@ final class SyncEngine
|
|||
}
|
||||
}
|
||||
|
||||
// Configure uploadOnly if function is called
|
||||
// By default, uploadOnly = false;
|
||||
void setUploadOnly()
|
||||
{
|
||||
uploadOnly = true;
|
||||
}
|
||||
|
||||
// Configure noRemoteDelete if function is called
|
||||
// By default, noRemoteDelete = false;
|
||||
// Meaning we will process local deletes to delete item on OneDrive
|
||||
|
@ -386,11 +396,12 @@ final class SyncEngine
|
|||
noRemoteDelete = true;
|
||||
}
|
||||
|
||||
// Configure uploadOnly if function is called
|
||||
// By default, uploadOnly = false;
|
||||
void setUploadOnly()
|
||||
// Configure localDeleteAfterUpload if function is called
|
||||
// By default, localDeleteAfterUpload = false;
|
||||
// Meaning we will not delete any local file after upload is successful
|
||||
void setLocalDeleteAfterUpload()
|
||||
{
|
||||
uploadOnly = true;
|
||||
localDeleteAfterUpload = true;
|
||||
}
|
||||
|
||||
// Configure singleDirectoryScope if function is called
|
||||
|
@ -2378,10 +2389,29 @@ final class SyncEngine
|
|||
if (!itemdb.selectByPath(path, defaultDriveId, item)) {
|
||||
// item is not in the database, upload new file
|
||||
uploadNewFile(path);
|
||||
|
||||
// did the upload fail?
|
||||
if (!uploadFailed) {
|
||||
// upload did not fail
|
||||
// Issue #763 - Delete local files after sync handling
|
||||
// are we in an --upload-only scenario?
|
||||
if (uploadOnly) {
|
||||
// are we in a delete local file after upload?
|
||||
if (localDeleteAfterUpload) {
|
||||
// Log that we are deleting a local item
|
||||
log.log("Removing local file as --upload-only & --remove-source-files configured");
|
||||
// are we in a --dry-run scenario?
|
||||
if (!dryRun) {
|
||||
// No --dry-run ... process local file delete
|
||||
log.vdebug("Removing local file: ", path);
|
||||
safeRemove(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// how much space is left on OneDrive after upload?
|
||||
remainingFreeSpace = (remainingFreeSpace - fileSize);
|
||||
log.vlog("Remaining free space: ", remainingFreeSpace);
|
||||
log.vlog("Remaining free space on OneDrive: ", remainingFreeSpace);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -3686,4 +3716,5 @@ final class SyncEngine
|
|||
log.vdebug("Generated Fake OneDrive Response: ", fakeResponse);
|
||||
return fakeResponse;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue