config: Move our tmp dir into config dir

This commit is contained in:
Hylke Bons 2016-06-25 21:12:40 +01:00
parent cde01d1166
commit 83ffa724d1
2 changed files with 14 additions and 13 deletions

View file

@ -343,9 +343,6 @@ namespace SparkleShare {
void DetectRepositoryRenames () void DetectRepositoryRenames ()
{ {
foreach (string group_path in Directory.GetDirectories (Config.FoldersPath)) { foreach (string group_path in Directory.GetDirectories (Config.FoldersPath)) {
if (group_path.EndsWith (".tmp"))
continue;
foreach (string folder_path in Directory.GetDirectories (group_path)) { foreach (string folder_path in Directory.GetDirectories (group_path)) {
string folder_name = Path.GetFileName (folder_path); string folder_name = Path.GetFileName (folder_path);
@ -557,17 +554,16 @@ namespace SparkleShare {
public void StartFetcher (SparkleFetcherInfo info) public void StartFetcher (SparkleFetcherInfo info)
{ {
Directory.Delete (Config.TmpPath, true);
Directory.CreateDirectory (Config.TmpPath);
File.SetAttributes (Config.TmpPath, File.GetAttributes (Config.TmpPath) | FileAttributes.Hidden);
string canonical_name = Path.GetFileName (info.RemotePath); string canonical_name = Path.GetFileName (info.RemotePath);
string backend = info.Backend; string backend = info.Backend;
if (string.IsNullOrEmpty (backend)) if (string.IsNullOrEmpty (backend))
backend = BaseFetcher.GetBackend (info.Address); backend = BaseFetcher.GetBackend (info.Address);
info.TargetDirectory = Path.Combine (Config.TmpPath, canonical_name); info.TargetDirectory = Path.Combine (Config.TmpPath, canonical_name);
if (Directory.Exists (info.TargetDirectory))
Directory.Delete (info.TargetDirectory);
try { try {
this.fetcher = (BaseFetcher) Activator.CreateInstance ( this.fetcher = (BaseFetcher) Activator.CreateInstance (
@ -678,7 +674,6 @@ namespace SparkleShare {
} }
} }
Directory.Delete (Config.TmpPath, true);
string backend = BaseFetcher.GetBackend (this.fetcher.RemoteUrl.ToString ()); string backend = BaseFetcher.GetBackend (this.fetcher.RemoteUrl.ToString ());
Config.AddFolder (target_folder_name, identifier, this.fetcher.RemoteUrl.ToString (), backend); Config.AddFolder (target_folder_name, identifier, this.fetcher.RemoteUrl.ToString (), backend);

View file

@ -27,9 +27,10 @@ namespace Sparkles {
public static Configuration DefaultConfiguration; public static Configuration DefaultConfiguration;
public static bool DebugMode = true; public static bool DebugMode = true;
public readonly string DirectoryPath; public readonly string DirectoryPath;
public readonly string FilePath; public readonly string FilePath;
public readonly string TmpPath; public readonly string TmpPath;
public readonly string BinPath;
public readonly string LogFilePath; public readonly string LogFilePath;
@ -58,12 +59,17 @@ namespace Sparkles {
FilePath = Path.Combine (config_path, config_file_name); FilePath = Path.Combine (config_path, config_file_name);
DirectoryPath = config_path; DirectoryPath = config_path;
BinPath = Path.Combine (config_path, "bin");
if (!Directory.Exists (BinPath))
Directory.CreateDirectory (BinPath);
string logs_path = Path.Combine (config_path, "logs"); string logs_path = Path.Combine (config_path, "logs");
int i = 1; int i = 1;
do { do {
LogFilePath = Path.Combine ( LogFilePath = Path.Combine (
logs_path, "debug_log_" + DateTime.Now.ToString ("yyyy-MM-dd") + "." + i + ".txt"); logs_path, "log_" + DateTime.Now.ToString ("yyyy-MM-dd") + "." + i + ".txt");
i++; i++;
@ -73,7 +79,7 @@ namespace Sparkles {
Directory.CreateDirectory (logs_path); Directory.CreateDirectory (logs_path);
// Delete logs older than a week // Delete logs older than a week
foreach (FileInfo file in new DirectoryInfo (logs_path).GetFiles ("debug_log*.txt")) { foreach (FileInfo file in new DirectoryInfo (logs_path).GetFiles ("log*.txt")) {
if (file.LastWriteTime < DateTime.Now.AddDays (-7)) if (file.LastWriteTime < DateTime.Now.AddDays (-7))
file.Delete (); file.Delete ();
} }
@ -103,7 +109,7 @@ namespace Sparkles {
} finally { } finally {
Load (FilePath); Load (FilePath);
TmpPath = Path.Combine (FoldersPath, ".tmp"); TmpPath = Path.Combine (DirectoryPath, "tmp");
Directory.CreateDirectory (TmpPath); Directory.CreateDirectory (TmpPath);
} }
} }