controller: Group new projects by domain name
This commit is contained in:
parent
fa5a5b5560
commit
aa380bbf8e
|
@ -327,16 +327,26 @@ namespace SparkleShare {
|
||||||
void CheckRepositories ()
|
void CheckRepositories ()
|
||||||
{
|
{
|
||||||
lock (this.check_repos_lock) {
|
lock (this.check_repos_lock) {
|
||||||
string path = Config.FoldersPath;
|
DetectRepositoryRenames ();
|
||||||
|
RemoveDeletedRepositories ();
|
||||||
|
}
|
||||||
|
|
||||||
// Detect any renames
|
FolderListChanged ();
|
||||||
foreach (string folder_path in Directory.GetDirectories (path)) {
|
}
|
||||||
string folder_name = Path.GetFileName (folder_path);
|
|
||||||
|
|
||||||
if (folder_name.Equals (".tmp"))
|
|
||||||
|
void DetectRepositoryRenames ()
|
||||||
|
{
|
||||||
|
foreach (string group_path in Directory.GetDirectories (Config.FoldersPath)) {
|
||||||
|
if (group_path.EndsWith (".tmp"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach (string folder_path in Directory.GetDirectories (group_path)) {
|
||||||
|
string folder_name = Path.GetFileName (folder_path);
|
||||||
|
|
||||||
|
if (Config.GetIdentifierForFolder (folder_name) != null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Config.GetIdentifierForFolder (folder_name) == null) {
|
|
||||||
string identifier_file_path = Path.Combine (folder_path, ".sparkleshare");
|
string identifier_file_path = Path.Combine (folder_path, ".sparkleshare");
|
||||||
|
|
||||||
if (!File.Exists (identifier_file_path))
|
if (!File.Exists (identifier_file_path))
|
||||||
|
@ -344,11 +354,13 @@ namespace SparkleShare {
|
||||||
|
|
||||||
string identifier = File.ReadAllText (identifier_file_path).Trim ();
|
string identifier = File.ReadAllText (identifier_file_path).Trim ();
|
||||||
|
|
||||||
if (Config.IdentifierExists (identifier)) {
|
if (!Config.IdentifierExists (identifier))
|
||||||
|
continue;
|
||||||
|
|
||||||
RemoveRepository (GetRepoByName (folder_name));
|
RemoveRepository (GetRepoByName (folder_name));
|
||||||
Config.RenameFolder (identifier, folder_name);
|
Config.RenameFolder (identifier, folder_name);
|
||||||
|
|
||||||
string new_folder_path = Path.Combine (path, folder_name);
|
string new_folder_path = Path.Combine (group_path, folder_name);
|
||||||
AddRepository (new_folder_path);
|
AddRepository (new_folder_path);
|
||||||
|
|
||||||
Logger.LogInfo ("Controller",
|
Logger.LogInfo ("Controller",
|
||||||
|
@ -357,7 +369,9 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove any deleted folders
|
|
||||||
|
void RemoveDeletedRepositories ()
|
||||||
|
{
|
||||||
foreach (string folder_name in Config.Folders) {
|
foreach (string folder_name in Config.Folders) {
|
||||||
string folder_path = new SparkleFolder (folder_name).FullPath;
|
string folder_path = new SparkleFolder (folder_name).FullPath;
|
||||||
|
|
||||||
|
@ -371,18 +385,6 @@ namespace SparkleShare {
|
||||||
AddRepository (folder_path);
|
AddRepository (folder_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove any duplicate folders
|
|
||||||
string previous_name = "";
|
|
||||||
foreach (string folder_name in Config.Folders) {
|
|
||||||
if (!string.IsNullOrEmpty (previous_name) && folder_name.Equals (previous_name))
|
|
||||||
Config.RemoveFolder (folder_name);
|
|
||||||
else
|
|
||||||
previous_name = folder_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
FolderListChanged ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -652,7 +654,12 @@ namespace SparkleShare {
|
||||||
if (suffix > 1)
|
if (suffix > 1)
|
||||||
target_folder_name += " (" + suffix + ")";
|
target_folder_name += " (" + suffix + ")";
|
||||||
|
|
||||||
string target_folder_path = Path.Combine (Config.FoldersPath, target_folder_name);
|
string group_folder_path = Path.Combine (Config.FoldersPath, this.fetcher.RemoteUrl.Host);
|
||||||
|
|
||||||
|
if (!Directory.Exists (group_folder_path))
|
||||||
|
Directory.CreateDirectory (group_folder_path);
|
||||||
|
|
||||||
|
string target_folder_path = Path.Combine (group_folder_path, target_folder_name);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Directory.Move (this.fetcher.TargetFolder, target_folder_path);
|
Directory.Move (this.fetcher.TargetFolder, target_folder_path);
|
||||||
|
|
|
@ -26,6 +26,7 @@ using MonoMac.AppKit;
|
||||||
|
|
||||||
using Sparkles;
|
using Sparkles;
|
||||||
using Sparkles.Git;
|
using Sparkles.Git;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace SparkleShare {
|
namespace SparkleShare {
|
||||||
|
|
||||||
|
@ -179,12 +180,13 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// We have to use our own custom made folder watcher, as
|
||||||
|
// System.IO.FileSystemWatcher fails watching subfolders on Mac
|
||||||
|
|
||||||
SparkleMacWatcher watcher;
|
SparkleMacWatcher watcher;
|
||||||
delegate void FileActivityTask ();
|
delegate void FileActivityTask ();
|
||||||
|
|
||||||
// We have to use our own custom made folder watcher, as
|
FileActivityTask MacFileActivityTask (BaseRepository repo, FileSystemEventArgs fse_args)
|
||||||
// System.IO.FileSystemWatcher fails watching subfolders on Mac
|
|
||||||
FileActivityTask MacActivityTask (BaseRepository repo, FileSystemEventArgs fse_args)
|
|
||||||
{
|
{
|
||||||
return delegate { new Thread (() => { repo.OnFileActivity (fse_args); }).Start (); };
|
return delegate { new Thread (() => { repo.OnFileActivity (fse_args); }).Start (); };
|
||||||
}
|
}
|
||||||
|
@ -193,30 +195,21 @@ namespace SparkleShare {
|
||||||
{
|
{
|
||||||
var triggered_repos = new List<string> ();
|
var triggered_repos = new List<string> ();
|
||||||
|
|
||||||
foreach (string file in changed_files_in_basedir) {
|
foreach (string file_path in changed_files_in_basedir) {
|
||||||
string repo_name;
|
string [] paths = file_path.Split (Path.DirectorySeparatorChar);
|
||||||
int path_sep_index = file.IndexOf (Path.DirectorySeparatorChar);
|
|
||||||
|
|
||||||
if (path_sep_index >= 0)
|
if (paths.Length < 2)
|
||||||
repo_name = file.Substring (0, path_sep_index);
|
|
||||||
else
|
|
||||||
repo_name = file;
|
|
||||||
|
|
||||||
repo_name = Path.GetFileNameWithoutExtension (repo_name);
|
|
||||||
BaseRepository repo = GetRepoByName (repo_name);
|
|
||||||
|
|
||||||
if (repo == null)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!triggered_repos.Contains (repo_name)) {
|
BaseRepository repo = GetRepoByName (paths [1]);
|
||||||
triggered_repos.Add (repo_name);
|
|
||||||
|
|
||||||
FileActivityTask task = MacActivityTask (repo,
|
if (repo != null && !triggered_repos.Contains (repo.Name)) {
|
||||||
new FileSystemEventArgs (WatcherChangeTypes.Changed, file, "Unknown"));
|
FileActivityTask task = MacFileActivityTask (repo,
|
||||||
|
new FileSystemEventArgs (WatcherChangeTypes.Changed, file_path, "Unknown"));
|
||||||
|
|
||||||
task ();
|
task ();
|
||||||
|
triggered_repos.Add (repo.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ namespace Sparkles {
|
||||||
|
|
||||||
public ChangeType Type;
|
public ChangeType Type;
|
||||||
public DateTime Timestamp;
|
public DateTime Timestamp;
|
||||||
public bool IsFolder = false;
|
public bool IsFolder;
|
||||||
|
|
||||||
public string Path;
|
public string Path;
|
||||||
public string MovedToPath;
|
public string MovedToPath;
|
||||||
|
@ -81,8 +81,10 @@ namespace Sparkles {
|
||||||
|
|
||||||
if (custom_path != null)
|
if (custom_path != null)
|
||||||
return Path.Combine (custom_path, Name);
|
return Path.Combine (custom_path, Name);
|
||||||
else
|
|
||||||
return Path.Combine (Configuration.DefaultConfig.FoldersPath, Name);
|
return Path.Combine (Configuration.DefaultConfig.FoldersPath,
|
||||||
|
new Uri (Configuration.DefaultConfig.GetUrlForFolder (Name)).Host,
|
||||||
|
Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue