Update how default path is set when running under systemd (#170)

* Update how default path is set when running under systemd
This commit is contained in:
abraunegg 2018-09-13 08:46:27 +10:00 committed by GitHub
parent 564a77fb4e
commit be1cb5e5ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 4 deletions

View file

@ -26,6 +26,7 @@ final class Config
void init()
{
// Default configuration directory
setValue("sync_dir", "~/OneDrive");
// Configure to skip ONLY temp files (~*.doc etc) by default
// Prior configuration was: .*|~*

View file

@ -1,6 +1,6 @@
import core.stdc.stdlib: EXIT_SUCCESS, EXIT_FAILURE;
import core.memory, core.time, core.thread;
import std.getopt, std.file, std.path, std.process, std.stdio, std.conv;
import std.getopt, std.file, std.path, std.process, std.stdio, std.conv, std.algorithm.searching;
import config, itemdb, monitor, onedrive, selective, sync, util;
import std.net.curl: CurlException;
static import log;
@ -206,10 +206,23 @@ int main(string[] args)
// Set the local path OneDrive root
string syncDir;
if ((environment.get("SHELL") == "") && (environment.get("USER") == "")){
// no shell or user set, so expandTilde() will fail
syncDir = homePath ~ "OneDrive";
// No shell or user set, so expandTilde() will fail - usually headless system running under init.d / systemd
// Did the user specify a 'different' sync dir by passing a value in?
if (syncDirName){
// was there a ~ in the passed in state? it will not work via init.d / systemd
if (canFind(cfg.getValue("sync_dir"),"~") ) {
// A ~ was found
syncDir = homePath ~ "/OneDrive";
} else {
// No ~ found in passed in state, use as is
syncDir = cfg.getValue("sync_dir");
}
} else {
// need to create a default as expanding ~ will not work
syncDir = homePath ~ "/OneDrive";
}
} else {
// A shell and user is set
// A shell and user is set, expand any ~ as this will be expanded if present
syncDir = expandTilde(cfg.getValue("sync_dir"));
}
log.vlog("All operations will be performed in: ", syncDir);