Skip to content

Commit

Permalink
Merge pull request #2011 from duplicati/feature/work_on_homedir_windows
Browse files Browse the repository at this point in the history
Additional workarounds to support variations in the Windows "Home" folder.
This should solve #1913 or at least add enough information that it can be fixed.
  • Loading branch information
kenkendk committed Oct 14, 2016
2 parents bc55763 + f042a46 commit 737976c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
15 changes: 8 additions & 7 deletions Duplicati/Library/Utility/FilterExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,15 +379,16 @@ public static void AnalyzeFilters(IFilter filter, out bool includes, out bool ex
includes = false;
excludes = false;

Tuple<bool, bool> cacheLookup;
Tuple<bool, bool> cacheLookup = null;

// Check for cached results
lock(_matchLock)
if (_matchFallbackLookup.TryGetValue(filter, out cacheLookup))
{
includes = cacheLookup.Item1;
excludes = cacheLookup.Item2;
}
if (filter != null)
lock(_matchLock)
if (_matchFallbackLookup.TryGetValue(filter, out cacheLookup))
{
includes = cacheLookup.Item1;
excludes = cacheLookup.Item2;
}

// Figure out what components are in the filter
if (cacheLookup == null)
Expand Down
42 changes: 29 additions & 13 deletions Duplicati/Server/SpecialFolders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public static class SpecialFolders
public static string ExpandEnvironmentVariables(string path)
{
foreach(var n in Nodes)
path = path.Replace(n.id, n.resolvedpath);
if (path.StartsWith(n.id))
path = path.Replace(n.id, n.resolvedpath);
return Library.Utility.Utility.ExpandEnvironmentVariables(path);
}

Expand Down Expand Up @@ -84,18 +85,22 @@ private static void TryAdd(List<Serializable.TreeNode> lst, string folder, strin
{
try
{
if (System.IO.Path.IsPathRooted(folder) && System.IO.Directory.Exists(folder))
if (!string.IsNullOrWhiteSpace(folder) && System.IO.Path.IsPathRooted(folder) && System.IO.Directory.Exists(folder))
{
lst.Add(new Serializable.TreeNode() {
id = id,
text = display,
leaf = false,
iconCls = "x-tree-icon-special",
resolvedpath = folder
});

PathMap[id] = folder;
DisplayMap[id] = display;
if (!PathMap.ContainsKey(id))
{
lst.Add(new Serializable.TreeNode()
{
id = id,
text = display,
leaf = false,
iconCls = "x-tree-icon-special",
resolvedpath = folder
});

PathMap[id] = folder;
DisplayMap[id] = display;
}
}
}
catch
Expand All @@ -107,7 +112,7 @@ static SpecialFolders()
{
var lst = new List<Serializable.TreeNode>();

if (!Library.Utility.Utility.IsClientLinux)
if (Library.Utility.Utility.IsClientWindows)
{
TryAdd(lst, Environment.SpecialFolder.MyDocuments, "%MY_DOCUMENTS%", "My Documents");
TryAdd(lst, Environment.SpecialFolder.MyMusic, "%MY_MUSIC%", "My Music");
Expand All @@ -116,13 +121,24 @@ static SpecialFolders()
TryAdd(lst, Environment.SpecialFolder.DesktopDirectory, "%DESKTOP%", "Desktop");
TryAdd(lst, Environment.SpecialFolder.ApplicationData, "%APPDATA%", "Application Data");
TryAdd(lst, Environment.SpecialFolder.UserProfile, "%HOME%", "Home");

try
{
// In case the UserProfile member points to junk
TryAdd(lst, System.IO.Path.Combine(Environment.GetEnvironmentVariable("HOMEDRIVE"), Environment.GetEnvironmentVariable("HOMEPATH")), "%HOME%", "Home");
}
catch
{
}

}
else
{
TryAdd(lst, Environment.SpecialFolder.MyDocuments, "%MY_DOCUMENTS%", "My Documents");
TryAdd(lst, Environment.SpecialFolder.MyMusic, "%MY_MUSIC%", "My Music");
TryAdd(lst, Environment.SpecialFolder.MyPictures, "%MY_PICTURES%", "My Pictures");
TryAdd(lst, Environment.SpecialFolder.DesktopDirectory, "%DESKTOP%", "Desktop");
TryAdd(lst, Environment.GetEnvironmentVariable("HOME"), "%HOME%", "Home");
TryAdd(lst, Environment.SpecialFolder.Personal, "%HOME%", "Home");
}

Expand Down
1 change: 1 addition & 0 deletions Duplicati/Server/WebServer/RESTMethods/SystemInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ private static object SystemData(RequestInfo info)
UsingAlternateUpdateURLs = Duplicati.Library.AutoUpdater.AutoUpdateSettings.UsesAlternateURLs,
LogLevels = Enum.GetNames(typeof(Duplicati.Library.Logging.LogMessageType)),
SuppressDonationMessages = Duplicati.Library.Main.Utility.SuppressDonationMessages,
SpecialFolders = from n in SpecialFolders.Nodes select new { ID = n.id, Path = n.resolvedpath },
BrowserLocale = new
{
Code = browserlanguage.Name,
Expand Down

0 comments on commit 737976c

Please sign in to comment.