config: Remove duplicate folders in the rare case they happen. Closes #978

This commit is contained in:
Hylke Bons 2012-09-21 18:04:47 +01:00
parent cf5bdf8ac8
commit 83f08666f2
2 changed files with 14 additions and 4 deletions

View file

@ -169,6 +169,8 @@ namespace SparkleLib {
foreach (XmlNode node_folder in SelectNodes ("/sparkleshare/folder"))
folders.Add (node_folder ["name"].InnerText);
folders.Sort ();
return folders;
}
}

View file

@ -90,8 +90,6 @@ namespace SparkleShare {
public List<string> Folders {
get {
List<string> folders = this.config.Folders;
folders.Sort ();
return folders;
}
}
@ -313,6 +311,7 @@ namespace SparkleShare {
lock (this.check_repos_lock) {
string path = this.config.FoldersPath;
// Detect any renames
foreach (string folder_path in Directory.GetDirectories (path)) {
string folder_name = Path.GetFileName (folder_path);
@ -340,6 +339,7 @@ namespace SparkleShare {
}
}
// Remove any deleted folders
foreach (string folder_name in this.config.Folders) {
string folder_path = new SparkleFolder (folder_name).FullPath;
@ -347,14 +347,22 @@ namespace SparkleShare {
this.config.RemoveFolder (folder_name);
RemoveRepository (folder_path);
SparkleLogger.LogInfo ("Controller",
"Removed folder '" + folder_name + "' from config");
SparkleLogger.LogInfo ("Controller", "Removed folder '" + folder_name + "' from config");
} else {
AddRepository (folder_path);
}
}
// Remove any duplicate folders
string previous_name = "";
foreach (string folder_name in this.config.Folders) {
if (!string.IsNullOrEmpty (previous_name) && folder_name.Equals (previous_name))
this.config.RemoveFolder (folder_name);
else
previous_name = folder_name;
}
FolderListChanged ();
}
}