mirror of
https://github.com/duplicati/duplicati.git
synced 2026-05-07 07:39:34 -04:00
Avoid performing tilde expansion.
The expansion being performed was often incorrect, as it's possible for the tilde character to appear as part of the path where it should not be expanded to the user's home directory. Properly supporting tilde expansion is complicated and requires additional study. Instead of supporting it only partially, we have decided to simplify things and just drop tilde expansion for now. See the discussion in issue #2619, as well as issues #2325 and #2555.
This commit is contained in:
@@ -977,13 +977,13 @@ namespace Duplicati.Library.Utility
|
||||
public static readonly string HOME_PATH = Environment.GetFolderPath(IsClientLinux ? Environment.SpecialFolder.Personal : Environment.SpecialFolder.UserProfile);
|
||||
|
||||
/// <summary>
|
||||
/// Expands environment variables, including the tilde character
|
||||
/// Expands environment variables.
|
||||
/// </summary>
|
||||
/// <returns>The expanded string.</returns>
|
||||
/// <param name="str">The string to expand.</param>
|
||||
public static string ExpandEnvironmentVariables(string str)
|
||||
{
|
||||
return Environment.ExpandEnvironmentVariables(str.Replace("~", HOME_PATH));
|
||||
return Environment.ExpandEnvironmentVariables(str);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -997,7 +997,7 @@ namespace Duplicati.Library.Utility
|
||||
private static readonly Regex ENVIRONMENT_VARIABLE_MATCHER_LINUX = new Regex(@"\$(?<name>\w+)|(\{(?<name>[^\}]+)\})");
|
||||
|
||||
/// <summary>
|
||||
/// Expands environment variables, including the tilde character, in a RegExp safe format
|
||||
/// Expands environment variables in a RegExp safe format
|
||||
/// </summary>
|
||||
/// <returns>The expanded string.</returns>
|
||||
/// <param name="str">The string to expand.</param>
|
||||
@@ -1012,9 +1012,7 @@ namespace Duplicati.Library.Utility
|
||||
// TODO: Should we switch to using the native format, instead of following the Windows scheme?
|
||||
//IsClientLinux ? ENVIRONMENT_VARIABLE_MATCHER_LINUX : ENVIRONMENT_VARIABLE_MATCHER_WINDOWS
|
||||
|
||||
ENVIRONMENT_VARIABLE_MATCHER_WINDOWS
|
||||
.Replace(str.Replace("~", Regex.Escape(HOME_PATH)), (m) =>
|
||||
Regex.Escape(lookup(m.Groups["name"].Value)));
|
||||
ENVIRONMENT_VARIABLE_MATCHER_WINDOWS.Replace(str, (m) => Regex.Escape(lookup(m.Groups["name"].Value)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Duplicati.UnitTest
|
||||
/// </summary>
|
||||
protected static readonly string BASEFOLDER =
|
||||
string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("UNITTEST_BASEFOLDER"))
|
||||
? Library.Utility.Utility.ExpandEnvironmentVariables(Path.Combine("~", "testdata"))
|
||||
? Path.Combine(Library.Utility.Utility.HOME_PATH, "testdata")
|
||||
: Environment.GetEnvironmentVariable("UNITTEST_BASEFOLDER");
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Duplicati.UnitTest
|
||||
private static readonly string SOURCE_FOLDERS =
|
||||
Path.Combine(
|
||||
string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("UNITTEST_BASEFOLDER"))
|
||||
? Library.Utility.Utility.ExpandEnvironmentVariables(Path.Combine("~", "testdata"))
|
||||
? Path.Combine(Library.Utility.Utility.HOME_PATH, "testdata")
|
||||
: Environment.GetEnvironmentVariable("UNITTEST_BASEFOLDER")
|
||||
, "DSMCBE");
|
||||
|
||||
|
||||
@@ -99,11 +99,6 @@ namespace Duplicati.UnitTest
|
||||
where !string.IsNullOrWhiteSpace(x)
|
||||
select Library.Utility.Utility.ExpandEnvironmentVariables(x)).ToArray();
|
||||
|
||||
//Expand the tilde to home folder on Linux/OSX
|
||||
if (Utility.IsClientLinux)
|
||||
folders = (from x in folders
|
||||
select x.Replace("~", Environment.GetFolderPath(Environment.SpecialFolder.Personal))).ToArray();
|
||||
|
||||
foreach (var f in folders)
|
||||
foreach (var n in f.Split(new char[] { System.IO.Path.PathSeparator }, StringSplitOptions.RemoveEmptyEntries))
|
||||
if (!System.IO.Directory.Exists(n))
|
||||
|
||||
Reference in New Issue
Block a user