From 459d1f27f619e5f3c7ac4e012efa30f2f48b5aba Mon Sep 17 00:00:00 2001 From: Dean Ferreyra Date: Sun, 7 Nov 2021 14:05:39 -0800 Subject: Formalize inclusion of code from https://github.com/dotnet Fix SystemIOWindows.PathGetFullPath per review comments. Add unit tests for SystemIOWindows.PathGetFullPath and SystemIOWindows.PrefixWithUNC. Also, fix a bug in the SystemIOWindows.PrefixWithUNC change that was exposed by these new unit tests. In BackendToolTests, remove unused [Setup] and [TearDown] methods. --- .../IO/DotNetRuntime.System.IO.Path.Windows.cs | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 Duplicati/Library/Common/IO/DotNetRuntime.System.IO.Path.Windows.cs (limited to 'Duplicati/Library/Common/IO/DotNetRuntime.System.IO.Path.Windows.cs') diff --git a/Duplicati/Library/Common/IO/DotNetRuntime.System.IO.Path.Windows.cs b/Duplicati/Library/Common/IO/DotNetRuntime.System.IO.Path.Windows.cs new file mode 100755 index 000000000..6a830a955 --- /dev/null +++ b/Duplicati/Library/Common/IO/DotNetRuntime.System.IO.Path.Windows.cs @@ -0,0 +1,59 @@ +// Adapted from https://raw.githubusercontent.com/dotnet/runtime/v5.0.12/src/libraries/System.Private.CoreLib/src/System/IO/Path.cs + +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// The MIT License (MIT) +// +// Copyright(c).NET Foundation and Contributors +// +// All rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; + +namespace Duplicati.Library.Common.IO +{ + public static class DotNetRuntimePathWindows + { + /// + /// Returns true if the path is fixed to a specific drive or UNC path. This method does no + /// validation of the path (URIs will be returned as relative as a result). + /// Returns false if the path specified is relative to the current drive or working directory. + /// + /// + /// Handles paths that use the alternate directory separator. It is a frequent mistake to + /// assume that rooted paths are not relative. This isn't the case. + /// "C:a" is drive relative- meaning that it will be resolved against the current directory + /// for C: (rooted, but relative). "C:\a" is rooted and not relative (the current directory + /// will not be used to modify the path). + /// + /// + /// Thrown if is null. + /// + public static bool IsPathFullyQualified(string path) + { + if (path == null) + throw new ArgumentNullException(nameof(path)); + + return !PathInternalWindows.IsPartiallyQualified(path); + } + } +} -- cgit v1.2.3