forked from dotnet/runtime
/
FileSystem.cs
51 lines (46 loc) · 2.06 KB
/
FileSystem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace System.IO
{
internal static partial class FileSystem
{
internal const UnixFileMode ValidUnixFileModes =
UnixFileMode.UserRead |
UnixFileMode.UserWrite |
UnixFileMode.UserExecute |
UnixFileMode.GroupRead |
UnixFileMode.GroupWrite |
UnixFileMode.GroupExecute |
UnixFileMode.OtherRead |
UnixFileMode.OtherWrite |
UnixFileMode.OtherExecute |
UnixFileMode.StickyBit |
UnixFileMode.SetGroup |
UnixFileMode.SetUser;
internal static void VerifyValidPath(string path, string argName)
{
ArgumentException.ThrowIfNullOrEmpty(path, argName);
if (path.Contains('\0'))
{
throw new ArgumentException(SR.Argument_NullCharInPath, argName);
}
}
internal static void MoveDirectory(string sourceFullPath, string destFullPath)
{
ReadOnlySpan<char> srcNoDirectorySeparator = Path.TrimEndingDirectorySeparator(sourceFullPath.AsSpan());
ReadOnlySpan<char> destNoDirectorySeparator = Path.TrimEndingDirectorySeparator(destFullPath.AsSpan());
// Don't allow the same path, except for changing the casing of the filename.
bool isCaseSensitiveRename = false;
if (srcNoDirectorySeparator.Equals(destNoDirectorySeparator, PathInternal.StringComparison))
{
if (PathInternal.IsCaseSensitive || // FileNames will be equal because paths are equal.
Path.GetFileName(srcNoDirectorySeparator).SequenceEqual(Path.GetFileName(destNoDirectorySeparator)))
{
throw new IOException(SR.IO_SourceDestMustBeDifferent);
}
isCaseSensitiveRename = true;
}
MoveDirectory(sourceFullPath, destFullPath, isCaseSensitiveRename);
}
}
}