added logout cmd line option

This commit is contained in:
skilion 2016-08-05 00:12:58 +02:00
parent 738536736a
commit c91decaa16
2 changed files with 18 additions and 4 deletions

View file

@ -12,6 +12,8 @@ int main(string[] args)
bool monitor;
// force a full resync
bool resync;
// remove the current user and sync state
bool logout;
// enable verbose logging
bool verbose;
@ -21,7 +23,8 @@ int main(string[] args)
std.getopt.config.bundling,
"monitor|m", "Keep monitoring for local and remote changes.", &monitor,
"resync", "Forget the last saved state, perform a full sync.", &resync,
"confdir", "Directory to use to store the configuration files.", &configDirName,
"logout", "Logout the current user.", &logout,
"confdir", "Set the directory to use to store the configuration files.", &configDirName,
"verbose|v", "Print more details, useful for debugging.", &log.verbose
);
if (opt.helpWanted) {
@ -39,13 +42,18 @@ int main(string[] args)
}
log.vlog("Loading config ...");
configDirName = expandTilde(configDirName);
if (!exists(configDirName)) mkdir(configDirName);
auto cfg = new config.Config(configDirName);
cfg.init();
if (resync) {
if (resync || logout) {
log.log("Deleting the saved status ...");
if (exists(cfg.databaseFilePath)) remove(cfg.databaseFilePath);
if (exists(cfg.statusTokenFilePath)) remove(cfg.statusTokenFilePath);
safeRemove(cfg.databaseFilePath);
safeRemove(cfg.statusTokenFilePath);
safeRemove(cfg.uploadStateFilePath);
if (logout) {
safeRemove(cfg.refreshTokenFilePath);
}
}
log.vlog("Initializing the OneDrive API ...");

View file

@ -32,6 +32,12 @@ void safeRename(const(char)[] path)
rename(path, newPath);
}
// delete the specified file without throwing an exception if it does not exists
void safeRemove(const(char)[] path)
{
if (exists(path)) remove(path);
}
// return the crc32 hex string of a file
string computeCrc32(string path)
{