Skip to content

Commit

Permalink
config: Remove duplicate folders in the rare case they happen. Closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
hbons committed Sep 21, 2012
1 parent 448d1b4 commit f5b7920
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions SparkleLib/SparkleConfig.cs
Expand Up @@ -169,6 +169,8 @@ private void CreateInitialConfig ()
foreach (XmlNode node_folder in SelectNodes ("/sparkleshare/folder"))
folders.Add (node_folder ["name"].InnerText);

folders.Sort ();

return folders;
}
}
Expand Down
16 changes: 12 additions & 4 deletions SparkleShare/SparkleControllerBase.cs
Expand Up @@ -90,8 +90,6 @@ public abstract class SparkleControllerBase {
public List<string> Folders {
get {
List<string> folders = this.config.Folders;
folders.Sort ();

return folders;
}
}
Expand Down Expand Up @@ -313,6 +311,7 @@ private void CheckRepositories ()
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);

Expand Down Expand Up @@ -340,21 +339,30 @@ private void CheckRepositories ()
}
}

// Remove any deleted folders
foreach (string folder_name in this.config.Folders) {
string folder_path = new SparkleFolder (folder_name).FullPath;

if (!Directory.Exists (folder_path)) {
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 ();
}
}
Expand Down

0 comments on commit f5b7920

Please sign in to comment.