Migrated to use the platform class.

This commit is contained in:
verhoek
2018-11-02 22:17:16 +01:00
parent b2cc18426c
commit 8bb406cd15
46 changed files with 271 additions and 225 deletions
+5 -5
View File
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Duplicati.Library.Common;
using FilterGroup = Duplicati.Library.Utility.FilterGroup;
namespace Duplicati.CommandLine
@@ -99,9 +99,9 @@ namespace Duplicati.CommandLine
tp = tp.Replace("%MONO%", Library.Utility.Utility.IsMono ? "mono " : "");
tp = tp.Replace("%APP_PATH%", System.IO.Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location));
tp = tp.Replace("%PATH_SEPARATOR%", System.IO.Path.PathSeparator.ToString());
tp = tp.Replace("%EXAMPLE_SOURCE_PATH%", Library.Utility.Utility.IsClientLinux ? "/source" : @"D:\source");
tp = tp.Replace("%EXAMPLE_SOURCE_FILE%", Library.Utility.Utility.IsClientLinux ? "/source/myfile.txt" : @"D:\source\file.txt");
tp = tp.Replace("%EXAMPLE_RESTORE_PATH%", Library.Utility.Utility.IsClientLinux ? "/restore" : @"D:\restore");
tp = tp.Replace("%EXAMPLE_SOURCE_PATH%", Platform.IsClientLinux ? "/source" : @"D:\source");
tp = tp.Replace("%EXAMPLE_SOURCE_FILE%", Platform.IsClientLinux ? "/source/myfile.txt" : @"D:\source\file.txt");
tp = tp.Replace("%EXAMPLE_RESTORE_PATH%", Platform.IsClientLinux ? "/restore" : @"D:\restore");
tp = tp.Replace("%ENCRYPTIONMODULES%", string.Join(", ", Library.DynamicLoader.EncryptionLoader.Keys));
tp = tp.Replace("%COMPRESSIONMODULES%", string.Join(", ", Library.DynamicLoader.CompressionLoader.Keys));
tp = tp.Replace("%DEFAULTENCRYPTIONMODULE%", opts.EncryptionModule);
@@ -111,7 +111,7 @@ namespace Duplicati.CommandLine
tp = tp.Replace("%FILTER_GROUPS_SHORT%", string.Join(Environment.NewLine + " ", metaGroupNames.Concat(Enum.GetNames(typeof(FilterGroup)).Except(metaGroupNames, StringComparer.OrdinalIgnoreCase).OrderBy(x => x, StringComparer.OrdinalIgnoreCase)).Select(group => "{" + group + "}")));
tp = tp.Replace("%FILTER_GROUPS_LONG%", Library.Utility.FilterGroups.GetOptionDescriptions(4, true));
if (Library.Utility.Utility.IsClientWindows)
if (Platform.IsClientWindows)
{
// These properties are only valid for Windows
tp = tp.Replace("%EXAMPLE_WILDCARD_DRIVE_SOURCE_PATH%", @"*:\source");
+4 -3
View File
@@ -1,4 +1,4 @@
#region Disclaimer / License
#region Disclaimer / License
// Copyright (C) 2015, The Duplicati Team
// http://www.duplicati.com, info@duplicati.com
//
@@ -24,7 +24,8 @@ using System.Linq;
using Duplicati.Library.Localization.Short;
using Duplicati.Library.Utility;
using System.IO;
using Duplicati.Library.Common;
namespace Duplicati.CommandLine
{
public class Program
@@ -51,7 +52,7 @@ namespace Duplicati.CommandLine
{
//If we are on Windows, append the bundled "win-tools" programs to the search path
//We add it last, to allow the user to override with other versions
if (Library.Utility.Utility.IsClientWindows)
if (Platform.IsClientWindows)
{
string wintools = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "win-tools");
Environment.SetEnvironmentVariable("PATH",
@@ -19,6 +19,7 @@ using System.IO;
using System.Linq;
using System.Collections.Generic;
using Duplicati.Library.Common.IO;
using Duplicati.Library.Common;
namespace Duplicati.CommandLine.RecoveryTool
{
@@ -148,7 +149,7 @@ namespace Duplicati.CommandLine.RecoveryTool
Console.WriteLine("Restoring {0} files to {1}", filecount, string.IsNullOrWhiteSpace(targetpath) ? "original position" : targetpath);
if (Library.Utility.Utility.IsClientLinux || largestprefix.Length > 0)
if (Platform.IsClientLinux || largestprefix.Length > 0)
largestprefix = Util.AppendDirSeparator(largestprefix);
if (!string.IsNullOrEmpty(largestprefix))
@@ -1,4 +1,4 @@
// Copyright (C) 2015, The Duplicati Team
// Copyright (C) 2015, The Duplicati Team
// http://www.duplicati.com, info@duplicati.com
//
// This library is free software; you can redistribute it and/or modify
@@ -16,7 +16,8 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#if __MonoCS__ || __WindowsGTK__ || ENABLE_GTK
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using Duplicati.Library.Common;
using Gdk;
using Gtk;
@@ -93,7 +94,7 @@ namespace Duplicati.GUI.TrayIcon
else
{
m_item = new ImageMenuItem(text);
if (!Duplicati.Library.Utility.Utility.IsClientOSX)
if (!Platform.IsClientOSX)
if (icon != MenuIcons.None) {
((ImageMenuItem)m_item).Image = GetIcon(icon);
@@ -268,7 +269,7 @@ namespace Duplicati.GUI.TrayIcon
{
if (!_images.ContainsKey(icon))
{
if (Duplicati.Library.Utility.Utility.IsClientOSX)
if (Platform.IsClientOSX)
{
switch (icon)
{
@@ -1,7 +1,8 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Duplicati.Library.Common;
using Duplicati.Library.Interface;
namespace Duplicati.GUI.TrayIcon
@@ -39,11 +40,11 @@ namespace Duplicati.GUI.TrayIcon
private static string GetDefaultToolKit()
{
// No longer using Cocoa directly as it fails on 32bit as well
if (Duplicati.Library.Utility.Utility.IsClientOSX)
if (Platform.IsClientOSX)
return TOOLKIT_RUMPS;
#if __MonoCS__ || __WindowsGTK__ || ENABLE_GTK
if (Duplicati.Library.Utility.Utility.IsClientLinux)
if (Platform.IsClientLinux)
{
if (SupportsAppIndicator)
return TOOLKIT_GTK_APP_INDICATOR;
@@ -73,7 +74,7 @@ namespace Duplicati.GUI.TrayIcon
List<string> args = new List<string>(_args);
Dictionary<string, string> options = Duplicati.Library.Utility.CommandLineParser.ExtractOptions(args);
if (Duplicati.Library.Utility.Utility.IsClientWindows && (Duplicati.Library.AutoUpdater.UpdaterManager.IsRunningInUpdateEnvironment || !Duplicati.Library.Utility.Utility.ParseBoolOption(options, DETACHED_PROCESS)))
if (Platform.IsClientWindows && (Duplicati.Library.AutoUpdater.UpdaterManager.IsRunningInUpdateEnvironment || !Duplicati.Library.Utility.Utility.ParseBoolOption(options, DETACHED_PROCESS)))
Duplicati.Library.Utility.Win32.AttachConsole(Duplicati.Library.Utility.Win32.ATTACH_PARENT_PROCESS);
foreach (string s in args)
@@ -111,7 +112,7 @@ namespace Duplicati.GUI.TrayIcon
if (!options.TryGetValue(TOOLKIT_OPTION, out toolkit))
{
#if !(__MonoCS__ || __WindowsGTK__ || ENABLE_GTK)
if (Library.Utility.Utility.IsClientLinux && !Library.Utility.Utility.IsClientOSX)
if (Platform.IsClientLinux && !Platform.IsClientOSX)
Console.WriteLine("Warning: this build does not support GTK, rebuild with ENABLE_GTK defined");
#endif
toolkit = GetDefaultToolKit();
@@ -444,7 +445,7 @@ namespace Duplicati.GUI.TrayIcon
new Duplicati.Library.Interface.CommandLineArgument(BROWSER_COMMAND_OPTION, CommandLineArgument.ArgumentType.String, "Sets the browser command", "Set this option to override the default browser detection"),
};
if (Duplicati.Library.Utility.Utility.IsClientWindows)
if (Platform.IsClientWindows)
{
args.Add(new Duplicati.Library.Interface.CommandLineArgument(DETACHED_PROCESS, CommandLineArgument.ArgumentType.String, "Runs the tray-icon detached", "This option runs the tray-icon in detached mode, meaning that the process will exit immediately and not send output to the console of the caller"));
}
@@ -21,7 +21,8 @@ using System.Linq;
using System.IO;
using System.Threading.Tasks;
using CoCoL;
using Duplicati.Library.Common;
namespace Duplicati.GUI.TrayIcon
{
public class RumpsRunner : TrayIconBase
@@ -130,7 +131,7 @@ namespace Duplicati.GUI.TrayIcon
public static bool CanRun()
{
if (!Library.Utility.Utility.IsClientOSX)
if (!Platform.IsClientOSX)
return false;
if (!File.Exists(SCRIPT_PATH) || !File.Exists(RUMPS_PYTHON))
@@ -22,6 +22,7 @@ using System.IO;
using System.Threading.Tasks;
using Duplicati.Library.Interface;
using Duplicati.Library.Common.IO;
using Duplicati.Library.Common;
namespace Duplicati.Library.AutoUpdater
{
@@ -124,14 +125,14 @@ namespace Duplicati.Library.AutoUpdater
System.IO.Path.Combine(InstalledBaseDir, "updates"),
});
if (Library.Utility.Utility.IsClientWindows)
if (Platform.IsClientWindows)
{
overrides.Add(System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), APPNAME, "updates"));
overrides.Add(System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), APPNAME, "updates"));
}
else
{
if (Library.Utility.Utility.IsClientOSX)
if (Platform.IsClientOSX)
overrides.Add(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Library", "Application Support", APPNAME, "updates"));
overrides.Add(System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), APPNAME, "updates"));
@@ -143,7 +144,7 @@ namespace Duplicati.Library.AutoUpdater
if (!string.IsNullOrWhiteSpace(programfiles))
legacypaths.Add(System.IO.Path.Combine(programfiles, APPNAME, "updates"));
if (Library.Utility.Utility.IsClientLinux)
if (Platform.IsClientLinux)
legacypaths.Add(System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), APPNAME, "updates"));
// The real attempts that we probe for
@@ -153,7 +154,7 @@ namespace Duplicati.Library.AutoUpdater
if (!string.IsNullOrWhiteSpace(programfiles) && !InstalledBaseDir.StartsWith(Util.AppendDirSeparator(programfiles), StringComparison.Ordinal))
attempts.Add(System.IO.Path.Combine(InstalledBaseDir, "updates"));
if (Library.Utility.Utility.IsClientOSX)
if (Platform.IsClientOSX)
attempts.Add(System.IO.Path.Combine("/", "Library", "Application Support", APPNAME, "updates"));
else
attempts.Add(System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), APPNAME, "updates"));
@@ -1083,7 +1084,7 @@ namespace Duplicati.Library.AutoUpdater
if (IsRunningInUpdateEnvironment)
{
// For some reason this does not work
//if (Library.Utility.Utility.IsClientWindows)
//if (Platform.IsClientWindows)
//Duplicati.Library.Utility.Win32.AttachConsole(Duplicati.Library.Utility.Win32.ATTACH_PARENT_PROCESS);
int r = 0;
@@ -1124,7 +1125,7 @@ namespace Duplicati.Library.AutoUpdater
pi.EnvironmentVariables["LOCALIZATION_FOLDER"] = InstalledBaseDir;
// On Windows, we manually redirect the streams
if (Library.Utility.Utility.IsClientWindows)
if (Platform.IsClientWindows)
{
pi.RedirectStandardError = true;
pi.RedirectStandardInput = true;
@@ -1133,7 +1134,7 @@ namespace Duplicati.Library.AutoUpdater
var proc = System.Diagnostics.Process.Start(pi);
Task tasks = null;
if (Library.Utility.Utility.IsClientWindows)
if (Platform.IsClientWindows)
{
// On Windows, we manually redirect the streams
tasks = Task.WhenAll(
@@ -22,6 +22,7 @@ using System.Collections.Generic;
using System.Runtime.InteropServices;
using Duplicati.Library.Interface;
using Duplicati.Library.Common.IO;
using Duplicati.Library.Common;
namespace Duplicati.Library.Backend
{
@@ -73,7 +74,7 @@ namespace Duplicati.Library.Backend
paths.AddRange(options[OPTION_ALTERNATE_PATHS].Split(new string[] { System.IO.Path.PathSeparator.ToString() }, StringSplitOptions.RemoveEmptyEntries));
//On windows we expand the drive letter * to all drives
if (!Utility.Utility.IsClientLinux)
if (!Platform.IsClientLinux)
{
System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
@@ -290,7 +291,7 @@ namespace Duplicati.Library.Backend
private System.IO.DriveInfo GetDrive()
{
string root;
if (Utility.Utility.IsClientLinux)
if (Platform.IsClientLinux)
{
string path = Util.AppendDirSeparator(systemIO.PathGetFullPath(m_path));
root = "/";
@@ -309,7 +310,7 @@ namespace Duplicati.Library.Backend
// On Windows, DriveInfo is only valid for lettered drives. (e.g., not for UNC paths and shares)
// So only attempt to get it if we aren't on Windows or if the root starts with a letter.
if (!Utility.Utility.IsClientWindows || (root.Length > 0 && char.IsLetter(root[0])))
if (!Platform.IsClientWindows || (root.Length > 0 && char.IsLetter(root[0])))
{
try
{
@@ -334,7 +335,7 @@ namespace Duplicati.Library.Backend
return new QuotaInfo(driveInfo.TotalSize, driveInfo.AvailableFreeSpace);
}
if (Utility.Utility.IsClientWindows)
if (Platform.IsClientWindows)
{
// If we can't get the DriveInfo on Windows, fallback to GetFreeDiskSpaceEx
// https://stackoverflow.com/questions/2050343/programmatically-determining-space-available-from-unc-path
+76
View File
@@ -28,5 +28,81 @@ namespace Duplicati.Library.Common
/// Gets a value indicating if the client is Windows based
/// </summary>
public static bool IsClientWindows => !IsClientLinux;
private static string UNAME;
/// <value>
/// Gets or sets a value indicating if the client is running OSX
/// </value>
public static bool IsClientOSX
{
get
{
// Sadly, Mono returns Unix when running on OSX
//return Environment.OSVersion.Platform == PlatformID.MacOSX;
if (!IsClientLinux)
return false;
try
{
if (UNAME == null)
{
var psi = new System.Diagnostics.ProcessStartInfo("uname")
{
RedirectStandardOutput = true,
RedirectStandardInput = false,
RedirectStandardError = false,
UseShellExecute = false
};
var pi = System.Diagnostics.Process.Start(psi);
pi.WaitForExit(5000);
if (pi.HasExited)
UNAME = pi.StandardOutput.ReadToEnd().Trim();
}
}
catch
{
}
return "Darwin".Equals(UNAME);
}
}
/// <value>
/// Gets the output of "uname -a" on Linux, or null on Windows
/// </value>
public static string UnameAll
{
get
{
if (!IsClientLinux)
return null;
try
{
var psi = new System.Diagnostics.ProcessStartInfo("uname", "-a")
{
RedirectStandardOutput = true,
RedirectStandardError = false,
RedirectStandardInput = false,
UseShellExecute = false
};
var pi = System.Diagnostics.Process.Start(psi);
pi.WaitForExit(5000);
if (pi.HasExited)
return pi.StandardOutput.ReadToEnd().Trim();
}
catch
{
// ignored
}
return null;
}
}
}
}
+3 -2
View File
@@ -24,6 +24,7 @@ using System;
using System.Collections.Generic;
using Duplicati.Library.Utility;
using Duplicati.Library.Common.IO;
using Duplicati.Library.Common;
namespace Duplicati.Library.Main
{
@@ -826,7 +827,7 @@ namespace Duplicati.Library.Main
{
List<string> expandedSources = new List<string>();
if (Library.Utility.Utility.IsClientWindows && (inputsource.StartsWith("*:", StringComparison.Ordinal) || inputsource.StartsWith("?:", StringComparison.Ordinal)))
if (Platform.IsClientWindows && (inputsource.StartsWith("*:", StringComparison.Ordinal) || inputsource.StartsWith("?:", StringComparison.Ordinal)))
{
// *: drive paths are only supported on Windows clients
// Lazily load the drive info
@@ -841,7 +842,7 @@ namespace Duplicati.Library.Main
expandedSources.Add(expandedSource);
}
}
else if (Library.Utility.Utility.IsClientWindows && inputsource.StartsWith(@"\\?\Volume{", StringComparison.OrdinalIgnoreCase))
else if (Platform.IsClientWindows && inputsource.StartsWith(@"\\?\Volume{", StringComparison.OrdinalIgnoreCase))
{
// In order to specify a drive by it's volume name, adopt the volume guid path syntax:
// \\?\Volume{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
@@ -16,6 +16,7 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using Duplicati.Library.Common;
using Duplicati.Library.Common.IO;
namespace Duplicati.Library.Main.Database
@@ -47,7 +48,7 @@ namespace Duplicati.Library.Main.Database
upcmd.Transaction = tr;
upcmd.ExecuteNonQuery(string.Format(@"CREATE TEMPORARY TABLE ""{0}"" (""ID"" INTEGER PRIMARY KEY, ""RealPath"" TEXT NOT NULL, ""Obfuscated"" TEXT NULL)", tablename));
upcmd.ExecuteNonQuery(string.Format(@"INSERT INTO ""{0}"" (""RealPath"") SELECT DISTINCT ""Path"" FROM ""File"" ORDER BY ""Path"" ", tablename));
upcmd.ExecuteNonQuery(string.Format(@"UPDATE ""{0}"" SET ""Obfuscated"" = ? || length(""RealPath"") || ? || ""ID"" || (CASE WHEN substr(""RealPath"", length(""RealPath"")) = ? THEN ? ELSE ? END) ", tablename), Library.Utility.Utility.IsClientLinux ? "/" : "X:\\", Util.DirectorySeparatorString, Util.DirectorySeparatorString, Util.DirectorySeparatorString, ".bin");
upcmd.ExecuteNonQuery(string.Format(@"UPDATE ""{0}"" SET ""Obfuscated"" = ? || length(""RealPath"") || ? || ""ID"" || (CASE WHEN substr(""RealPath"", length(""RealPath"")) = ? THEN ? ELSE ? END) ", tablename), Platform.IsClientLinux ? "/" : "X:\\", Util.DirectorySeparatorString, Util.DirectorySeparatorString, Util.DirectorySeparatorString, ".bin");
/*long id = 1;
using(var rd = cmd.ExecuteReader(string.Format(@"SELECT ""RealPath"", ""Obfuscated"" FROM ""{0}"" ", tablename)))
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Duplicati.Library.Common;
using Duplicati.Library.Common.IO;
using Duplicati.Library.Main.Volumes;
@@ -389,14 +390,14 @@ namespace Duplicati.Library.Main.Database
// defaults when restoring cross OS, e.g. backup on Linux, restore on Windows
//This is mostly meaningless, and the user really should use --restore-path
if (Library.Utility.Utility.IsClientLinux && dirsep == "\\")
if (Platform.IsClientLinux && dirsep == "\\")
{
// For Win -> Linux, we remove the colon from the drive letter, and use the drive letter as root folder
cmd.ExecuteNonQuery(string.Format(@"UPDATE ""{0}"" SET ""Targetpath"" = CASE WHEN SUBSTR(""Path"", 2, 1) == "":"" THEN ""\\"" || SUBSTR(""Path"", 1, 1) || SUBSTR(""Path"", 3) ELSE ""Path"" END", m_tempfiletable));
cmd.ExecuteNonQuery(string.Format(@"UPDATE ""{0}"" SET ""Targetpath"" = CASE WHEN SUBSTR(""Path"", 1, 2) == ""\\"" THEN ""\\"" || SUBSTR(""Path"", 2) ELSE ""Path"" END", m_tempfiletable));
}
else if (Library.Utility.Utility.IsClientWindows && dirsep == "/")
else if (Platform.IsClientWindows && dirsep == "/")
{
// For Linux -> Win, we use the temporary folder's drive as the root path
cmd.ExecuteNonQuery(string.Format(@"UPDATE ""{0}"" SET ""Targetpath"" = CASE WHEN SUBSTR(""Path"", 1, 1) == ""/"" THEN ? || SUBSTR(""Path"", 2) ELSE ""Path"" END", m_tempfiletable), Util.AppendDirSeparator(System.IO.Path.GetPathRoot(Library.Utility.TempFolder.SystemTempPath)).Replace("\\", "/"));
@@ -427,10 +428,10 @@ namespace Duplicati.Library.Main.Database
}
// Cross-os path remapping support
if (Library.Utility.Utility.IsClientLinux && dirsep == "\\")
if (Platform.IsClientLinux && dirsep == "\\")
// For Win paths on Linux
cmd.ExecuteNonQuery(string.Format(@"UPDATE ""{0}"" SET ""TargetPath"" = REPLACE(""TargetPath"", ""\"", ""/"")", m_tempfiletable));
else if (Library.Utility.Utility.IsClientWindows && dirsep == "/")
else if (Platform.IsClientWindows && dirsep == "/")
// For Linux paths on Windows
cmd.ExecuteNonQuery(string.Format(@"UPDATE ""{0}"" SET ""TargetPath"" = REPLACE(REPLACE(""TargetPath"", ""\"", ""_""), ""/"", ""\"")", m_tempfiletable));
+4 -3
View File
@@ -1,4 +1,4 @@
// Copyright (C) 2015, The Duplicati Team
// Copyright (C) 2015, The Duplicati Team
// http://www.duplicati.com, info@duplicati.com
//
@@ -19,7 +19,8 @@ using System;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json.Serialization;
using Duplicati.Library.Common;
namespace Duplicati.Library.Main
{
public static class DatabaseLocator
@@ -58,7 +59,7 @@ namespace Duplicati.Library.Main
var folder = System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Duplicati");
if (Duplicati.Library.Utility.Utility.IsClientWindows)
if (Platform.IsClientWindows)
{
var newlocation = System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Duplicati");
@@ -33,6 +33,7 @@ using System.Threading;
using Duplicati.Library.Snapshots;
using Duplicati.Library.Utility;
using Duplicati.Library.Common.IO;
using Duplicati.Library.Common;
namespace Duplicati.Library.Main.Operation
{
@@ -84,7 +85,7 @@ namespace Duplicati.Library.Main.Operation
Logging.Log.WriteWarningMessage(LOGTAG, "SnapshotFailed", ex, Strings.Common.SnapshotFailedError(ex.ToString()));
}
return Library.Utility.Utility.IsClientLinux ?
return Platform.IsClientLinux ?
(Library.Snapshots.ISnapshotService)new Duplicati.Library.Snapshots.NoSnapshotLinux()
:
(Library.Snapshots.ISnapshotService)new Duplicati.Library.Snapshots.NoSnapshotWindows();
@@ -18,7 +18,8 @@ using System;
using System.Collections.Generic;
using Duplicati.Library.Interface;
using System.Linq;
using Duplicati.Library.Common;
namespace Duplicati.Library.Main.Operation
{
internal static class SystemInfoHandler
@@ -39,7 +40,7 @@ namespace Duplicati.Library.Main.Operation
yield return string.Format("Current Version folder {0}", System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));
yield return string.Format("OS: {0}", Environment.OSVersion);
yield return string.Format("Uname: {0}", Duplicati.Library.Utility.Utility.UnameAll);
yield return string.Format("Uname: {0}", Platform.UnameAll);
yield return string.Format("64bit: {0} ({1})", Environment.Is64BitOperatingSystem, Environment.Is64BitProcess);
yield return string.Format("Machinename: {0}", Environment.MachineName);
+9 -8
View File
@@ -16,6 +16,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Linq;
using Duplicati.Library.Common;
using Duplicati.Library.Utility;
namespace Duplicati.Library.Main
@@ -98,7 +99,7 @@ namespace Duplicati.Library.Main
/// </summary>
private void StartSleepPrevention()
{
if (Duplicati.Library.Utility.Utility.IsClientWindows)
if (Platform.IsClientWindows)
{
try
{
@@ -110,7 +111,7 @@ namespace Duplicati.Library.Main
Logging.Log.WriteWarningMessage(LOGTAG, "SleepPrevetionError", ex, "Failed to set sleep prevention");
}
}
else if (Duplicati.Library.Utility.Utility.IsClientOSX)
else if (Platform.IsClientOSX)
{
try
{
@@ -144,7 +145,7 @@ namespace Duplicati.Library.Main
{
var pid = System.Diagnostics.Process.GetCurrentProcess().Id;
if (Duplicati.Library.Utility.Utility.IsClientWindows)
if (Platform.IsClientWindows)
{
var handle = System.Diagnostics.Process.GetCurrentProcess().Handle;
@@ -181,7 +182,7 @@ namespace Duplicati.Library.Main
}
else
{
if (Duplicati.Library.Utility.Utility.IsClientOSX)
if (Platform.IsClientOSX)
{
var data = RunProcessAndGetResult("ps", $"-onice -p {pid}");
if (data.Item1 != 0)
@@ -251,7 +252,7 @@ namespace Duplicati.Library.Main
/// </summary>
private void StopSleepPrevention()
{
if (Duplicati.Library.Utility.Utility.IsClientWindows)
if (Platform.IsClientWindows)
{
try
{
@@ -266,7 +267,7 @@ namespace Duplicati.Library.Main
Logging.Log.WriteWarningMessage(LOGTAG, "SleepPrevetionError", ex, "Failed to set sleep prevention");
}
}
else if (Duplicati.Library.Utility.Utility.IsClientOSX)
else if (Platform.IsClientOSX)
{
try
{
@@ -299,7 +300,7 @@ namespace Duplicati.Library.Main
/// </summary>
private void DeactivateBackgroundIOPriority()
{
if (Duplicati.Library.Utility.Utility.IsClientWindows)
if (Platform.IsClientWindows)
{
try
{
@@ -342,7 +343,7 @@ namespace Duplicati.Library.Main
var pid = System.Diagnostics.Process.GetCurrentProcess().Id;
Tuple<int, string, string> data;
if (Duplicati.Library.Utility.Utility.IsClientOSX)
if (Platform.IsClientOSX)
{
// TODO: We can only give lower priority, thus not reset it ...
data = RunProcessAndGetResult($"renice", $"{m_originalNiceLevel} -p {pid}");
@@ -1,4 +1,4 @@
#region Disclaimer / License
#region Disclaimer / License
// Copyright (C) 2015, The Duplicati Team
// http://www.duplicati.com, info@duplicati.com
//
@@ -20,7 +20,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using Duplicati.Library.Common;
namespace Duplicati.Library.Modules.Builtin
{
public class ConsolePasswordInput : Duplicati.Library.Interface.IGenericModule
@@ -62,7 +63,7 @@ namespace Duplicati.Library.Modules.Builtin
catch (InvalidOperationException)
{
// Handle redirect issues on Windows only
if (!Library.Utility.Utility.IsClientWindows)
if (!Platform.IsClientWindows)
throw;
commandlineOptions["passphrase"] = ReadPassphraseFromStdin(confirm);
@@ -108,6 +108,10 @@
<Project>{D4C37C33-5E73-4B56-B2C3-DC4A6BAA36BB}</Project>
<Name>Duplicati.Library.OAuthHelper</Name>
</ProjectReference>
<ProjectReference Include="..\..\IO\Duplicati.Library.Common.csproj">
<Project>{D63E53E4-A458-4C2F-914D-92F715F58ACF}</Project>
<Name>Duplicati.Library.Common</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Duplicati.snk" />
@@ -1,4 +1,4 @@
#region Disclaimer / License
#region Disclaimer / License
// Copyright (C) 2015, The Duplicati Team
// http://www.duplicati.com, info@duplicati.com
//
@@ -21,6 +21,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Duplicati.Library.Common;
using Duplicati.Library.Snapshots;
namespace Duplicati.Library.Modules.Builtin
@@ -53,7 +54,7 @@ namespace Duplicati.Library.Modules.Builtin
public bool LoadAsDefault
{
get { return Utility.Utility.IsClientWindows; }
get { return Platform.IsClientWindows; }
}
public IList<Interface.ICommandLineArgument> SupportedCommands
@@ -72,7 +73,7 @@ namespace Duplicati.Library.Modules.Builtin
public Dictionary<string, string> ParseSourcePaths(ref string[] paths, ref string filter, Dictionary<string, string> commandlineOptions)
{
// Early exit in case we are non-windows to prevent attempting to load Windows-only components
if (!Utility.Utility.IsClientWindows)
if (!Platform.IsClientWindows)
{
Logging.Log.WriteWarningMessage(LOGTAG, "HyperVWindowsOnly", null, "Hyper-V backup works only on Windows OS");
@@ -216,7 +217,7 @@ namespace Duplicati.Library.Modules.Builtin
public bool ContainFilesForBackup(string[] paths)
{
if (paths == null || !Utility.Utility.IsClientWindows)
if (paths == null || !Platform.IsClientWindows)
return false;
return paths.Where(x => !string.IsNullOrWhiteSpace(x)).Any(x => x.Equals(m_HyperVPathAllRegExp, StringComparison.OrdinalIgnoreCase) || Regex.IsMatch(x, m_HyperVPathGuidRegExp, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant));
@@ -1,4 +1,4 @@
#region Disclaimer / License
#region Disclaimer / License
// Copyright (C) 2015, The Duplicati Team
// http://www.duplicati.com, info@duplicati.com
//
@@ -21,6 +21,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Duplicati.Library.Common;
using Duplicati.Library.Snapshots;
namespace Duplicati.Library.Modules.Builtin
@@ -54,7 +55,7 @@ namespace Duplicati.Library.Modules.Builtin
public bool LoadAsDefault
{
get { return Utility.Utility.IsClientWindows; }
get { return Platform.IsClientWindows; }
}
public IList<Interface.ICommandLineArgument> SupportedCommands
@@ -73,7 +74,7 @@ namespace Duplicati.Library.Modules.Builtin
public Dictionary<string, string> ParseSourcePaths(ref string[] paths, ref string filter, Dictionary<string, string> commandlineOptions)
{
// Early exit in case we are non-windows to prevent attempting to load Windows-only components
if (!Utility.Utility.IsClientWindows)
if (!Platform.IsClientWindows)
{
Logging.Log.WriteWarningMessage(LOGTAG, "MSSqlWindowsOnly", null, "Microsoft SQL Server databases backup works only on Windows OS");
@@ -214,7 +215,7 @@ namespace Duplicati.Library.Modules.Builtin
public bool ContainFilesForBackup(string[] paths)
{
if (paths == null || !Utility.Utility.IsClientWindows)
if (paths == null || !Platform.IsClientWindows)
return false;
return paths.Where(x => !string.IsNullOrWhiteSpace(x)).Any(x => x.Equals(m_MSSQLPathAllRegExp, StringComparison.OrdinalIgnoreCase) || Regex.IsMatch(x, m_MSSQLPathDBRegExp, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant));
@@ -88,5 +88,9 @@
<Project>{D10A5FC0-11B4-4E70-86AA-8AEA52BD9798}</Project>
<Name>Duplicati.Library.Logging</Name>
</ProjectReference>
<ProjectReference Include="..\IO\Duplicati.Library.Common.csproj">
<Project>{D63E53E4-A458-4C2F-914D-92F715F58ACF}</Project>
<Name>Duplicati.Library.Common</Name>
</ProjectReference>
</ItemGroup>
</Project>
@@ -1,4 +1,4 @@
#region Disclaimer / License
#region Disclaimer / License
// Copyright (C) 2015, The Duplicati Team
// http://www.duplicati.com, info@duplicati.com
//
@@ -19,7 +19,8 @@
#endregion
using System;
using System.IO;
using Duplicati.Library.Common;
namespace Duplicati.Library.SQLiteHelper
{
public static class SQLiteLoader
@@ -264,14 +265,14 @@ namespace Duplicati.Library.SQLiteHelper
// Check if SQLite database exists before opening a connection to it.
// This information is used to 'fix' permissions on a newly created file.
var fileExists = false;
if (!Library.Utility.Utility.IsClientWindows)
if (!Platform.IsClientWindows)
fileExists = File.Exists(path);
con.ConnectionString = "Data Source=" + path;
con.Open();
// If we are non-Windows, make the file only accessible by the current user
if (!Library.Utility.Utility.IsClientWindows && !fileExists)
if (!Platform.IsClientWindows && !fileExists)
SetUnixPermissionUserRWOnly(path);
}
+2 -1
View File
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Management;
using Duplicati.Library.Common;
using Duplicati.Library.Common.IO;
namespace Duplicati.Library.Snapshots
@@ -93,7 +94,7 @@ namespace Duplicati.Library.Snapshots
{
Guests = new List<HyperVGuest>();
if (!Utility.Utility.IsClientWindows)
if (!Platform.IsClientWindows)
{
IsHyperVInstalled = false;
IsVSSWriterSupported = false;
+3 -2
View File
@@ -1,4 +1,5 @@
using Duplicati.Library.Common.IO;
using Duplicati.Library.Common;
using Duplicati.Library.Common.IO;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -84,7 +85,7 @@ namespace Duplicati.Library.Snapshots
{
m_DBs = new List<MSSQLDB>();
if (!Utility.Utility.IsClientWindows)
if (!Platform.IsClientWindows)
{
IsMSSQLInstalled = false;
return;
+4 -3
View File
@@ -1,4 +1,4 @@
#region Disclaimer / License
#region Disclaimer / License
// Copyright (C) 2015, The Duplicati Team
// http://www.duplicati.com, info@duplicati.com
//
@@ -20,7 +20,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using Duplicati.Library.Common;
namespace Duplicati.Library.Snapshots
{
static class Program
@@ -104,7 +105,7 @@ Where <test-folder> is the folder where files will be locked/created etc");
}
Console.WriteLine("Creating snapshot for folder: {0}", args[0]);
Console.WriteLine("If this fails, try to run as " + (Utility.Utility.IsClientLinux ? "root" : "Administrator"));
Console.WriteLine("If this fails, try to run as " + (Platform.IsClientLinux ? "root" : "Administrator"));
using (ISnapshotService snapshot = SnapshotUtility.CreateSnapshot(new[] { args[0] }, options))
{
Console.WriteLine("Attempting to read locked file via snapshot");
@@ -1,4 +1,4 @@
#region Disclaimer / License
#region Disclaimer / License
// Copyright (C) 2015, The Duplicati Team
// http://www.duplicati.com, info@duplicati.com
//
@@ -20,6 +20,7 @@
using System.Collections.Generic;
using System.IO;
using Duplicati.Library.Common;
using Duplicati.Library.Common.IO;
namespace Duplicati.Library.Snapshots
@@ -38,7 +39,7 @@ namespace Duplicati.Library.Snapshots
public static ISnapshotService CreateSnapshot(IEnumerable<string> folders, Dictionary<string, string> options)
{
return
Utility.Utility.IsClientLinux
Platform.IsClientLinux
? CreateLinuxSnapshot(folders)
: CreateWindowsSnapshot(folders, options);
+2 -1
View File
@@ -26,6 +26,7 @@ using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using Duplicati.Library.Common;
using Duplicati.Library.Common.IO;
using Microsoft.Win32.SafeHandles;
@@ -91,7 +92,7 @@ namespace Duplicati.Library.Snapshots
/// <param name="volumeRoot">The root volume where the USN lookup is performed</param>
internal USNJournal(string volumeRoot)
{
if (Utility.Utility.IsClientLinux)
if (Platform.IsClientLinux)
throw new Interface.UserInformationException(Strings.USNHelper.LinuxNotSupportedError, "UsnOnLinuxNotSupported");
m_volume = Util.AppendDirSeparator(volumeRoot);
@@ -62,6 +62,10 @@
<Project>{D10A5FC0-11B4-4E70-86AA-8AEA52BD9798}</Project>
<Name>Duplicati.Library.Logging</Name>
</ProjectReference>
<ProjectReference Include="..\IO\Duplicati.Library.Common.csproj">
<Project>{D63E53E4-A458-4C2F-914D-92F715F58ACF}</Project>
<Name>Duplicati.Library.Common</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
@@ -17,7 +17,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Duplicati.Library.Common;
namespace Duplicati.Library.UsageReporter
{
/// <summary>
@@ -71,11 +72,11 @@ namespace Duplicati.Library.UsageReporter
{
get
{
if (!Utility.Utility.IsClientLinux)
if (!Platform.IsClientLinux)
{
return Environment.OSVersion.ToString();
}
else if (Utility.Utility.IsClientOSX)
else if (Platform.IsClientOSX)
{
var m = RunProgramAndReadOutput("sw_vers", null);
if (m != null)
+4 -3
View File
@@ -18,7 +18,8 @@ using System;
using Newtonsoft.Json;
using System.Linq;
using System.Collections.Generic;
using Duplicati.Library.Common;
namespace Duplicati.Library.UsageReporter
{
/// <summary>
@@ -44,9 +45,9 @@ namespace Duplicati.Library.UsageReporter
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
private static void DoInitOS()
{
if (Library.Utility.Utility.IsClientOSX)
if (Platform.IsClientOSX)
Cached_OSType = "OSX";
else if (Library.Utility.Utility.IsClientLinux)
else if (Platform.IsClientLinux)
Cached_OSType = "Linux";
else if (new PlatformID[] {
PlatformID.Win32NT,
+13 -11
View File
@@ -17,7 +17,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Duplicati.Library.Common.IO;
using Duplicati.Library.Common;
using Duplicati.Library.Localization.Short;
namespace Duplicati.Library.Utility
@@ -111,12 +113,12 @@ namespace Duplicati.Library.Utility
/// <summary>
/// Regex escaped string for the AltDirectorySeparatorChar
/// </summary>
private static readonly string RegexEscapedAltDirectorySeparatorChar = System.Text.RegularExpressions.Regex.Escape(Util.AltDirectorySeparatorString);
private static readonly string RegexEscapedAltDirectorySeparatorChar = System.Text.RegularExpressions.Regex.Escape(Common.IO.Util.AltDirectorySeparatorString);
/// <summary>
/// Regex escaped string for the DirectorySeparatorChar
/// </summary>
private static readonly string RegexEscapedDirectorySeparatorChar = System.Text.RegularExpressions.Regex.Escape(Util.DirectorySeparatorString);
private static readonly string RegexEscapedDirectorySeparatorChar = System.Text.RegularExpressions.Regex.Escape(Common.IO.Util.DirectorySeparatorString);
/// <summary>
/// Gets the list of alternate aliases which can refer to this group.
@@ -229,11 +231,11 @@ namespace Duplicati.Library.Utility
{
IEnumerable<string> osFilters;
if (Utility.IsClientOSX)
if (Platform.IsClientOSX)
osFilters = CreateOSXFilters(group);
else if (Utility.IsClientLinux)
else if (Platform.IsClientLinux)
osFilters = CreateLinuxFilters(group);
else if (Utility.IsClientWindows)
else if (Platform.IsClientWindows)
osFilters = CreateWindowsFilters(group);
else
throw new ArgumentException("Unknown operating system?");
@@ -269,7 +271,7 @@ namespace Duplicati.Library.Utility
if (n.Length > 2 && char.IsLetter(n[0]) && n[1] == ':' && wildcardRootWindowsPaths.Contains(n.Substring(2)))
continue;
else if (prev != null && prev.EndsWith(Util.DirectorySeparatorString, StringComparison.Ordinal) && n.StartsWith(prev, Utility.ClientFilenameStringComparison))
else if (prev != null && prev.EndsWith(Common.IO.Util.DirectorySeparatorString, StringComparison.Ordinal) && n.StartsWith(prev, Utility.ClientFilenameStringComparison))
continue;
else
yield return prev = n;
@@ -357,7 +359,7 @@ namespace Duplicati.Library.Utility
yield return windir;
// Also exclude "C:\Windows.old\"
yield return Util.AppendDirSeparator(windir.TrimEnd('\\', '/') + ".old");
yield return Common.IO.Util.AppendDirSeparator(windir.TrimEnd('\\', '/') + ".old");
}
}
@@ -582,7 +584,7 @@ namespace Duplicati.Library.Utility
// Meaning a filter for 'C:\Windows' won't match 'C:\Windows\'.
// So this makes sure special folder's filter's have a trailing directory separator.
// (Alternatively, this could append '*' to all folder filters.)
return Util.AppendDirSeparator(filter);
return Common.IO.Util.AppendDirSeparator(filter);
}
else
{
@@ -621,7 +623,7 @@ namespace Duplicati.Library.Utility
private static IEnumerable<string> GetOSXExcludeFiles()
{
var res = new List<string>();
if (Utility.IsClientOSX)
if (Platform.IsClientOSX)
{
try
{
@@ -679,7 +681,7 @@ namespace Duplicati.Library.Utility
/// <returns>The list of paths to exclude.</returns>
private static string[] GetWindowsRegistryFilters()
{
if (Utility.IsClientWindows)
if (Platform.IsClientWindows)
{
// One Windows, filters may also be stored in the registry
try
@@ -15,6 +15,8 @@
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using Duplicati.Library.Common;
namespace Duplicati.Library.Utility.Power
{
public static class PowerSupply
@@ -31,15 +33,15 @@ namespace Duplicati.Library.Utility.Power
IPowerSupplyState state;
// Since IsClientLinux returns true when on Mac OS X, we need to check IsClientOSX first.
if (Utility.IsClientOSX)
if (Platform.IsClientOSX)
{
state = new MacOSPowerSupplyState();
}
else if (Utility.IsClientLinux)
else if (Platform.IsClientLinux)
{
state = new LinuxPowerSupplyState();
}
else if (Utility.IsClientWindows)
else if (Platform.IsClientWindows)
{
state = new WindowsPowerSupplyState();
}
@@ -1,4 +1,4 @@
#region Disclaimer / License
#region Disclaimer / License
// Copyright (C) 2015, The Duplicati Team
// http://www.duplicati.com, info@duplicati.com
//
@@ -18,11 +18,10 @@
//
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
using Duplicati.Library.Common;
namespace Duplicati.Library.Utility
{
public class SslCertificateValidator
@@ -37,7 +36,7 @@ namespace Duplicati.Library.Utility
public SslPolicyErrors SslError { get { return m_errors; } }
public InvalidCertificateException(string certificate, SslPolicyErrors error)
: base(Strings.SslCertificateValidator.VerifyCertificateException(error, certificate) + (Utility.IsClientLinux ? Strings.SslCertificateValidator.MonoHelpSSL : ""))
: base(Strings.SslCertificateValidator.VerifyCertificateException(error, certificate) + (Platform.IsClientLinux ? Strings.SslCertificateValidator.MonoHelpSSL : ""))
{
m_certificate = certificate;
m_errors = error;
+5 -4
View File
@@ -1,4 +1,4 @@
#region Disclaimer / License
#region Disclaimer / License
// Copyright (C) 2015, The Duplicati Team
// http://www.duplicati.com, info@duplicati.com
//
@@ -20,7 +20,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using Duplicati.Library.Common;
namespace Duplicati.Library.Utility
{
public static class UrlUtility
@@ -54,7 +55,7 @@ namespace Duplicati.Library.Utility
browserprogram = SystemBrowser;
//Fallback is to just show the window in a browser
if (Utility.IsClientOSX)
if (Platform.IsClientOSX)
{
try
{
@@ -67,7 +68,7 @@ namespace Duplicati.Library.Utility
ErrorHandler(string.Format("Unable to open a browser window, please manually visit: \r\n{0}", url));
}
}
else if (Utility.IsClientLinux)
else if (Platform.IsClientLinux)
{
try
{
+7 -89
View File
@@ -22,6 +22,7 @@ using System.Threading.Tasks;
using System.Text;
using System.Text.RegularExpressions;
using Duplicati.Library.Common.IO;
using Duplicati.Library.Common;
namespace Duplicati.Library.Utility
{
@@ -436,13 +437,13 @@ namespace Duplicati.Library.Utility
if (last == -1 || last == 0 && len == 0)
return null;
if (last == 0 && !IsClientWindows)
if (last == 0 && !Platform.IsClientWindows)
return Util.DirectorySeparatorString;
var parent = path.Substring(0, last);
if (forceTrailingDirectorySeparator ||
IsClientWindows && parent.Length == 2 && parent[1] == ':' && char.IsLetter(parent[0]))
Platform.IsClientWindows && parent.Length == 2 && parent[1] == ':' && char.IsLetter(parent[0]))
{
parent += Path.DirectorySeparatorChar;
}
@@ -824,7 +825,7 @@ namespace Duplicati.Library.Utility
public static bool Which(string appname)
{
if (!IsClientLinux)
if (!Platform.IsClientLinux)
return false;
try
@@ -851,89 +852,6 @@ namespace Duplicati.Library.Utility
return false;
}
private static string UNAME;
/// <value>
/// Gets or sets a value indicating if the client is running OSX
/// </value>
public static bool IsClientOSX
{
get
{
// Sadly, Mono returns Unix when running on OSX
//return Environment.OSVersion.Platform == PlatformID.MacOSX;
if (!IsClientLinux)
return false;
try
{
if (UNAME == null)
{
var psi = new System.Diagnostics.ProcessStartInfo("uname")
{
RedirectStandardOutput = true,
RedirectStandardInput = false,
RedirectStandardError = false,
UseShellExecute = false
};
var pi = System.Diagnostics.Process.Start(psi);
pi.WaitForExit(5000);
if (pi.HasExited)
UNAME = pi.StandardOutput.ReadToEnd().Trim();
}
}
catch
{
}
return "Darwin".Equals(UNAME);
}
}
/// <value>
/// Gets the output of "uname -a" on Linux, or null on Windows
/// </value>
public static string UnameAll
{
get
{
if (!IsClientLinux)
return null;
try
{
var psi = new System.Diagnostics.ProcessStartInfo("uname", "-a")
{
RedirectStandardOutput = true,
RedirectStandardError = false,
RedirectStandardInput = false,
UseShellExecute = false
};
var pi = System.Diagnostics.Process.Start(psi);
pi.WaitForExit(5000);
if (pi.HasExited)
return pi.StandardOutput.ReadToEnd().Trim();
}
catch
{
// ignored
}
return null;
}
}
/// <value>
/// Gets or sets a value indicating if the client is Linux/Unix based
/// </value>
public static bool IsClientLinux => Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX;
/// <summary>
/// Gets a value indicating if the client is Windows based
/// </summary>
public static bool IsClientWindows => !IsClientLinux;
/// <value>
/// Returns a value indicating if the filesystem, is case sensitive
@@ -948,7 +866,7 @@ namespace Duplicati.Library.Utility
// TODO: This should probably be determined by filesystem rather than OS,
// OSX can actually have the disks formated as Case Sensitive, but insensitive is default
CachedIsFSCaseSensitive = ParseBool(str, () => IsClientLinux && !IsClientOSX);
CachedIsFSCaseSensitive = ParseBool(str, () => Platform.IsClientLinux && !Platform.IsClientOSX);
}
return CachedIsFSCaseSensitive.Value;
@@ -1026,7 +944,7 @@ namespace Duplicati.Library.Utility
/// <summary>
/// The path to the users home directory
/// </summary>
public static readonly string HOME_PATH = Environment.GetFolderPath(IsClientLinux ? Environment.SpecialFolder.Personal : Environment.SpecialFolder.UserProfile);
public static readonly string HOME_PATH = Environment.GetFolderPath(Platform.IsClientLinux ? Environment.SpecialFolder.Personal : Environment.SpecialFolder.UserProfile);
/// <summary>
/// Regexp for matching environment variables on Windows (%VAR%)
@@ -1495,7 +1413,7 @@ namespace Duplicati.Library.Utility
if (string.IsNullOrWhiteSpace(arg))
return arg;
if (!IsClientWindows)
if (!Platform.IsClientWindows)
{
// We could consider using single quotes that prevents all expansions
//if (!allowEnvExpansion)
+5 -4
View File
@@ -1,4 +1,4 @@
// Copyright (C) 2015, The Duplicati Team
// Copyright (C) 2015, The Duplicati Team
// http://www.duplicati.com, info@duplicati.com
//
@@ -23,7 +23,8 @@ using System.Security.Cryptography.X509Certificates;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Pkcs;
using Org.BouncyCastle.Security;
using Duplicati.Library.Common;
namespace Duplicati.Server.Database
{
public class ServerSettings
@@ -495,7 +496,7 @@ namespace Duplicati.Server.Database
if (String.IsNullOrEmpty(m_values[CONST.SERVER_SSL_CERTIFICATE]))
return null;
if (Library.Utility.Utility.IsClientWindows)
if (Platform.IsClientWindows)
return new X509Certificate2(Convert.FromBase64String(m_values[CONST.SERVER_SSL_CERTIFICATE]));
else
{
@@ -527,7 +528,7 @@ namespace Duplicati.Server.Database
}
else
{
if (Library.Utility.Utility.IsClientWindows)
if (Platform.IsClientWindows)
lock (m_connection.m_lock)
m_values[CONST.SERVER_SSL_CERTIFICATE] = Convert.ToBase64String(value.Export(X509ContentType.Pkcs12));
else
+4 -3
View File
@@ -1,4 +1,4 @@
#region Disclaimer / License
#region Disclaimer / License
// Copyright (C) 2015, The Duplicati Team
// http://www.duplicati.com, info@duplicati.com
//
@@ -20,7 +20,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using Duplicati.Library.Common;
namespace Duplicati.Server
{
/// <summary>
@@ -210,7 +211,7 @@ namespace Duplicati.Server
try
{
if (!Library.Utility.Utility.IsClientLinux)
if (!Platform.IsClientLinux)
RegisterHibernateMonitor();
}
catch { }
+5 -4
View File
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Duplicati.Library.Common;
using Duplicati.Library.Common.IO;
namespace Duplicati.Server
@@ -173,7 +174,7 @@ namespace Duplicati.Server
{
//If we are on Windows, append the bundled "win-tools" programs to the search path
//We add it last, to allow the user to override with other versions
if (Library.Utility.Utility.IsClientWindows)
if (Platform.IsClientWindows)
{
Environment.SetEnvironmentVariable("PATH",
Environment.GetEnvironmentVariable("PATH") +
@@ -513,7 +514,7 @@ namespace Duplicati.Server
//If you change the key, please note that you need to supply the same
// key when restoring the setup, as the setup being backed up will
// be encrypted as well.
if (!Library.Utility.Utility.IsClientLinux && string.IsNullOrEmpty(dbPassword))
if (!Platform.IsClientLinux && string.IsNullOrEmpty(dbPassword))
dbPassword = Library.AutoUpdater.AutoUpdateSettings.AppName + "_Key_42";
// Allow override of the environment variables from the commandline
@@ -552,7 +553,7 @@ namespace Duplicati.Server
//
serverDataFolder = System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Library.AutoUpdater.AutoUpdateSettings.AppName);
if (Duplicati.Library.Utility.Utility.IsClientWindows)
if (Platform.IsClientWindows)
{
var localappdata = System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Library.AutoUpdater.AutoUpdateSettings.AppName);
@@ -749,7 +750,7 @@ namespace Duplicati.Server
});
if (!Duplicati.Library.Utility.Utility.IsClientLinux)
if (!Platform.IsClientLinux)
lst.Add(new Duplicati.Library.Interface.CommandLineArgument("server-encryption-key", Duplicati.Library.Interface.CommandLineArgument.ArgumentType.Password, Strings.Program.ServerencryptionkeyShort, Strings.Program.ServerencryptionkeyLong(DB_KEY_ENV_NAME, "unencrypted-database"), Library.AutoUpdater.AutoUpdateSettings.AppName + "_Key_42"));
return lst.ToArray();
+6 -5
View File
@@ -20,6 +20,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using Duplicati.Library.Common;
using Duplicati.Library.Common.IO;
using Duplicati.Library.Utility;
@@ -140,7 +141,7 @@ namespace Duplicati.Server
try
{
if (Library.Utility.Utility.IsClientLinux)
if (Platform.IsClientLinux)
temp_fs = UnixSupport.File.OpenExclusive(m_lockfilename, System.IO.FileAccess.Write);
else
temp_fs = System.IO.File.Open(m_lockfilename, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None);
@@ -188,7 +189,7 @@ namespace Duplicati.Server
//HACK: the unix file lock does not allow us to read the file length when the file is locked
if (new System.IO.FileInfo(m_lockfilename).Length == 0)
if (!Library.Utility.Utility.IsClientLinux)
if (!Platform.IsClientLinux)
throw new Exception("The file was locked, but had no data");
//Notify the other process that we have started
@@ -196,7 +197,7 @@ namespace Duplicati.Server
//Write out the commandline arguments
string[] cmdargs = System.Environment.GetCommandLineArgs();
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(Library.Utility.Utility.IsClientLinux ? UnixSupport.File.OpenExclusive(filename, System.IO.FileAccess.Write) : new System.IO.FileStream(filename, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write, System.IO.FileShare.None)))
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(Platform.IsClientLinux ? UnixSupport.File.OpenExclusive(filename, System.IO.FileAccess.Write) : new System.IO.FileStream(filename, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write, System.IO.FileShare.None)))
for (int i = 1; i < cmdargs.Length; i++) //Skip the first, as that is the filename
sw.WriteLine(cmdargs[i]);
@@ -237,7 +238,7 @@ namespace Duplicati.Server
// needs a little time to create+lock the file. This is not really a fix, but an
// ugly workaround. This functionality is only used to allow a new instance to signal
// the running instance, so errors here would only affect that functionality
if (Library.Utility.Utility.IsClientLinux)
if (Platform.IsClientLinux)
System.Threading.Thread.Sleep(1000);
do
@@ -249,7 +250,7 @@ namespace Duplicati.Server
return;
List<string> args = new List<string>();
using (System.IO.StreamReader sr = new System.IO.StreamReader(Duplicati.Library.Utility.Utility.IsClientLinux ? UnixSupport.File.OpenExclusive(e.FullPath, System.IO.FileAccess.ReadWrite) : new System.IO.FileStream(e.FullPath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.None)))
using (System.IO.StreamReader sr = new System.IO.StreamReader(Platform.IsClientLinux ? UnixSupport.File.OpenExclusive(e.FullPath, System.IO.FileAccess.ReadWrite) : new System.IO.FileStream(e.FullPath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.None)))
while(!sr.EndOfStream)
args.Add(sr.ReadLine());
+2 -1
View File
@@ -19,6 +19,7 @@ using System;
using System.Linq;
using System.Collections.Generic;
using Duplicati.Library.Common.IO;
using Duplicati.Library.Common;
namespace Duplicati.Server
{
@@ -113,7 +114,7 @@ namespace Duplicati.Server
{
var lst = new List<Serializable.TreeNode>();
if (Library.Utility.Utility.IsClientWindows)
if (Platform.IsClientWindows)
{
TryAdd(lst, Environment.SpecialFolder.MyDocuments, "%MY_DOCUMENTS%", "My Documents");
TryAdd(lst, Environment.SpecialFolder.MyMusic, "%MY_MUSIC%", "My Music");
@@ -20,6 +20,7 @@ using System.Linq;
using System.IO;
using Duplicati.Library.Snapshots;
using Duplicati.Library.Common.IO;
using Duplicati.Library.Common;
namespace Duplicati.Server.WebServer.RESTMethods
{
@@ -67,7 +68,7 @@ namespace Duplicati.Server.WebServer.RESTMethods
path = SpecialFolders.ExpandEnvironmentVariables(path);
if (Duplicati.Library.Utility.Utility.IsClientLinux && !path.StartsWith("/", StringComparison.Ordinal))
if (Platform.IsClientLinux && !path.StartsWith("/", StringComparison.Ordinal))
{
info.ReportClientError("The path parameter must start with a forward-slash", System.Net.HttpStatusCode.BadRequest);
return;
@@ -106,7 +107,7 @@ namespace Duplicati.Server.WebServer.RESTMethods
IEnumerable<Serializable.TreeNode> res;
if (!Library.Utility.Utility.IsClientLinux && (path.Equals("/") || path.Equals("")))
if (!Platform.IsClientLinux && (path.Equals("/") || path.Equals("")))
{
res = DriveInfo.GetDrives()
.Where(di =>
@@ -20,7 +20,8 @@ using Duplicati.Library.Interface;
using System.Linq;
using System.Security.Principal;
using Duplicati.Library.Snapshots;
using Duplicati.Library.Common;
namespace Duplicati.Server.WebServer.RESTMethods
{
public class HyperV : IRESTMethodGET, IRESTMethodDocumented
@@ -28,7 +29,7 @@ namespace Duplicati.Server.WebServer.RESTMethods
public void GET(string key, RequestInfo info)
{
// Early exit in case we are non-windows to prevent attempting to load Windows-only components
if (Library.Utility.Utility.IsClientWindows)
if (Platform.IsClientWindows)
RealGET(key, info);
else
info.OutputOK(new string[0]);
@@ -20,7 +20,8 @@ using Duplicati.Library.Interface;
using System.Linq;
using System.Security.Principal;
using Duplicati.Library.Snapshots;
using Duplicati.Library.Common;
namespace Duplicati.Server.WebServer.RESTMethods
{
public class MSSQL : IRESTMethodGET, IRESTMethodDocumented
@@ -28,7 +29,7 @@ namespace Duplicati.Server.WebServer.RESTMethods
public void GET(string key, RequestInfo info)
{
// Early exit in case we are non-windows to prevent attempting to load Windows-only components
if (Library.Utility.Utility.IsClientWindows)
if (Platform.IsClientWindows)
RealGET(key, info);
else
info.OutputOK(new string[0]);
@@ -18,7 +18,8 @@ using System;
using System.Linq;
using System.Collections.Generic;
using Duplicati.Library.Interface;
using Duplicati.Library.Common;
namespace Duplicati.Server.WebServer.RESTMethods
{
public class SystemInfo : IRESTMethodGET, IRESTMethodPOST, IRESTMethodDocumented
@@ -75,7 +76,7 @@ namespace Duplicati.Server.WebServer.RESTMethods
DefaultUpdateChannel = Duplicati.Library.AutoUpdater.AutoUpdateSettings.DefaultUpdateChannel,
DefaultUsageReportLevel = Duplicati.Library.UsageReporter.Reporter.DefaultReportLevel,
ServerTime = DateTime.Now,
OSType = Library.Utility.Utility.IsClientLinux ? (Library.Utility.Utility.IsClientOSX ? "OSX" : "Linux") : "Windows",
OSType = Platform.IsClientLinux ? (Platform.IsClientOSX ? "OSX" : "Linux") : "Windows",
DirectorySeparator = System.IO.Path.DirectorySeparatorChar,
PathSeparator = System.IO.Path.PathSeparator,
CaseSensitiveFilesystem = Duplicati.Library.Utility.Utility.IsFSCaseSensitive,
+5 -4
View File
@@ -20,6 +20,7 @@ using NUnit.Framework;
using Duplicati.Library.Common.IO;
using Duplicati.Library.Utility;
using Duplicati.Library.Common;
namespace Duplicati.UnitTest
{
@@ -36,7 +37,7 @@ namespace Duplicati.UnitTest
[Test]
public void TestGetPathRootWithLongPath()
{
var pathRoot = Utility.IsClientWindows ? "C:\\" : "/";
var pathRoot = Platform.IsClientWindows ? "C:\\" : "/";
var root = SystemIO.IO_OS.GetPathRoot(LongPath(pathRoot));
Assert.AreEqual(pathRoot, root);
@@ -45,7 +46,7 @@ namespace Duplicati.UnitTest
[Test]
public void TestUncBehaviourOfAlphaFS()
{
if (!Utility.IsClientWindows)
if (!Platform.IsClientWindows)
{
return;
}
@@ -68,7 +69,7 @@ namespace Duplicati.UnitTest
[Test]
public void TestGetFilesWhenDirectoryDoesNotExist()
{
var pathRoot = Utility.IsClientWindows ? "C:\\" : "/";
var pathRoot = Platform.IsClientWindows ? "C:\\" : "/";
var longPath = LongPath(pathRoot);
if (SystemIO.IO_OS.DirectoryExists(longPath))
@@ -83,7 +84,7 @@ namespace Duplicati.UnitTest
[Test]
public void TestGetDirectoriesWhenDirectoryDoesNotExist()
{
var pathRoot = Utility.IsClientWindows ? "C:\\" : "/";
var pathRoot = Platform.IsClientWindows ? "C:\\" : "/";
var longPath = LongPath(pathRoot);
if (SystemIO.IO_OS.DirectoryExists(longPath))
+2 -1
View File
@@ -18,6 +18,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Duplicati.Library.Common;
using Duplicati.Library.Interface;
using NUnit.Framework;
@@ -158,7 +159,7 @@ namespace Duplicati.UnitTest
private string CreateScript(int exitcode, string stderr = null, string stdout = null, int sleeptime = 0)
{
var id = Guid.NewGuid().ToString("N").Substring(0, 6);
if (Library.Utility.Utility.IsClientWindows)
if (Platform.IsClientWindows)
{
var commands = new List<string>();
if (!string.IsNullOrWhiteSpace(stdout))