mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-04 15:03:24 +02:00
* Implement a capability to ignore a folder when a special file (.nosync) is present
This commit is contained in:
parent
2d54f3e4d1
commit
ba834368ca
13
README.md
13
README.md
|
@ -468,6 +468,17 @@ Year 2
|
|||
```
|
||||
**Note:** after changing the sync_list, you must perform a full re-synchronization by adding `--resync` to your existing command line - for example: `onedrive --synchronize --resync`
|
||||
|
||||
### Skipping directories from syncing
|
||||
There are several mechanisms available to 'skip' a directory from scanning:
|
||||
* Utilise 'skip_file'
|
||||
* Utilise 'sync_list'
|
||||
|
||||
One further method is to add a '.nosync' empty file to any folder. When this file is present, adding `--check-for-nosync` to your command line will now make the sync process skip any folder where the '.nosync' file is present.
|
||||
|
||||
To make this a permanent change to always skip folders when a '.nosync' empty file is present, add the following to your config file:
|
||||
|
||||
Example: `check_nosync = "true"`
|
||||
|
||||
### Shared folders
|
||||
Folders shared with you can be synced by adding them to your OneDrive. To do that open your Onedrive, go to the Shared files list, right click on the folder you want to sync and then click on "Add to my OneDrive".
|
||||
|
||||
|
@ -598,6 +609,8 @@ Options:
|
|||
|
||||
--check-for-nomount
|
||||
Check for the presence of .nosync in the syncdir root. If found, do not perform sync.
|
||||
--check-for-nosync
|
||||
Check for the presence of .nosync in each directory. If found, skip directory from sync.
|
||||
--confdir ARG
|
||||
Set the directory used to store the configuration files
|
||||
--create-directory ARG
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH ONEDRIVE "1" "January 2019" "2.2.5" "User Commands"
|
||||
.TH ONEDRIVE "1" "February 2019" "2.2.5" "User Commands"
|
||||
.SH NAME
|
||||
onedrive \- folder synchronization with OneDrive
|
||||
.SH SYNOPSIS
|
||||
|
@ -21,6 +21,9 @@ Without any option given, no sync is done and the program exits.
|
|||
\fB\-\-check\-for\-nomount\fP
|
||||
Check for the presence of .nosync in the syncdir root. If found, do not perform sync.
|
||||
.TP
|
||||
\fB\-\-check\-for\-nosync\fP
|
||||
Check for the presence of .nosync in each directory. If found, skip directory from sync.
|
||||
.TP
|
||||
\fB\-\-confdir\fP ARG
|
||||
Set the directory used to store the configuration files
|
||||
.TP
|
||||
|
|
|
@ -47,6 +47,8 @@ final class Config
|
|||
setValue("min_notif_changes", "5");
|
||||
// Frequency of log messages in monitor, ie after n sync runs ship out a log message
|
||||
setValue("monitor_log_frequency", "5");
|
||||
// Check if we should ignore a directory if a special file (.nosync) is present
|
||||
setValue("check_nosync", "false");
|
||||
|
||||
if (!load(userConfigFilePath)) {
|
||||
// What was the reason for failure?
|
||||
|
|
13
src/main.d
13
src/main.d
|
@ -22,6 +22,8 @@ int main(string[] args)
|
|||
// Application Option Variables
|
||||
// Add a check mounts option to resolve https://github.com/abraunegg/onedrive/issues/8
|
||||
bool checkMount = false;
|
||||
// Check if we should ignore a directory if a special file (.nosync) is present - https://github.com/abraunegg/onedrive/issues/163
|
||||
bool checkNoSync = false;
|
||||
// configuration directory
|
||||
string configDirName;
|
||||
// Create a single root directory on OneDrive
|
||||
|
@ -90,6 +92,7 @@ int main(string[] args)
|
|||
std.getopt.config.bundling,
|
||||
std.getopt.config.caseSensitive,
|
||||
"check-for-nomount", "Check for the presence of .nosync in the syncdir root. If found, do not perform sync.", &checkMount,
|
||||
"check-for-nosync", "Check for the presence of .nosync in each directory. If found, skip directory from sync.", &checkNoSync,
|
||||
"confdir", "Set the directory used to store the configuration files", &configDirName,
|
||||
"create-directory", "Create a directory on OneDrive - no sync will be performed.", &createDirectory,
|
||||
"destination-directory", "Destination directory for renamed or move on OneDrive - no sync will be performed.", &destinationDirectory,
|
||||
|
@ -212,6 +215,12 @@ int main(string[] args)
|
|||
}
|
||||
|
||||
// command line parameters to override default 'config' & take precedence
|
||||
// Set the client to skip specific directories if .nosync is found AND ONLY if --check-for-nosync was passed in
|
||||
if (checkNoSync) {
|
||||
log.vdebug("CLI override to set check_nosync to: true");
|
||||
cfg.setValue("check_nosync", "true");
|
||||
}
|
||||
|
||||
// Set the client to skip dot files & folders if --skip-dot-files was passed in
|
||||
if (skipDotFiles) {
|
||||
// The user passed in an alternate skip_dotfiles as to what was either in 'config' file or application default
|
||||
|
@ -308,6 +317,7 @@ int main(string[] args)
|
|||
}
|
||||
|
||||
// Config Options
|
||||
writeln("Config option 'check_nosync' = ", cfg.getValue("check_nosync"));
|
||||
writeln("Config option 'sync_dir' = ", syncDir);
|
||||
writeln("Config option 'skip_file' = ", cfg.getValue("skip_file"));
|
||||
writeln("Config option 'skip_dotfiles' = ", cfg.getValue("skip_dotfiles"));
|
||||
|
@ -554,7 +564,8 @@ int main(string[] args)
|
|||
|
||||
// initialise the monitor class
|
||||
if (cfg.getValue("skip_symlinks") == "true") skipSymlinks = true;
|
||||
if (!downloadOnly) m.init(cfg, verbose, skipSymlinks);
|
||||
if (cfg.getValue("check_nosync") == "true") checkNoSync = true;
|
||||
if (!downloadOnly) m.init(cfg, verbose, skipSymlinks, checkNoSync);
|
||||
// monitor loop
|
||||
immutable auto checkInterval = dur!"seconds"(to!long(cfg.getValue("monitor_interval")));
|
||||
immutable auto logInterval = to!long(cfg.getValue("monitor_log_frequency"));
|
||||
|
|
|
@ -32,6 +32,8 @@ final class Monitor
|
|||
private void[] buffer;
|
||||
// skip symbolic links
|
||||
bool skip_symlinks;
|
||||
// check for .nosync if enabled
|
||||
bool check_nosync;
|
||||
|
||||
private SelectiveSync selectiveSync;
|
||||
|
||||
|
@ -46,10 +48,11 @@ final class Monitor
|
|||
this.selectiveSync = selectiveSync;
|
||||
}
|
||||
|
||||
void init(Config cfg, bool verbose, bool skip_symlinks)
|
||||
void init(Config cfg, bool verbose, bool skip_symlinks, bool check_nosync)
|
||||
{
|
||||
this.verbose = verbose;
|
||||
this.skip_symlinks = skip_symlinks;
|
||||
this.check_nosync = check_nosync;
|
||||
|
||||
assert(onDirCreated && onFileChanged && onDelete && onMove);
|
||||
fd = inotify_init();
|
||||
|
@ -91,6 +94,14 @@ final class Monitor
|
|||
}
|
||||
}
|
||||
|
||||
// Do we need to check for .nosync? Only if check_nosync is true
|
||||
if (check_nosync) {
|
||||
if (exists(buildNormalizedPath(dirname) ~ "/.nosync")) {
|
||||
log.vlog("Skipping watching path - .nosync found & --check-for-nosync enabled: ", buildNormalizedPath(dirname));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
add(dirname);
|
||||
foreach(DirEntry entry; dirEntries(dirname, SpanMode.shallow, false)) {
|
||||
if (entry.isDir) {
|
||||
|
|
|
@ -1345,6 +1345,14 @@ final class SyncEngine
|
|||
}
|
||||
}
|
||||
|
||||
// Do we need to check for .nosync? Only if --check-for-nosync was passed in
|
||||
if (cfg.getValue("check_nosync") == "true") {
|
||||
if (exists(path ~ "/.nosync")) {
|
||||
log.vlog("Skipping item - .nosync found & --check-for-nosync enabled: ", path);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isSymlink(path)) {
|
||||
// if config says so we skip all symlinked items
|
||||
if (cfg.getValue("skip_symlinks") == "true") {
|
||||
|
|
Loading…
Reference in a new issue