Fix access control check with scrubbing in NetCore builds. (#1079)

This commit is contained in:
Michael Pysson 2019-10-21 19:11:46 -07:00
Родитель 931c5fba09
Коммит 220e5bc85b
3 изменённых файлов: 20 добавлений и 8 удалений

Просмотреть файл

@ -1509,7 +1509,6 @@ namespace BuildXL.Native.IO.Windows
Contract.Requires(!string.IsNullOrWhiteSpace(path));
path = FileSystemWin.ToLongPathIfExceedMaxPath(path);
#if NET_FRAMEWORK
FileSystemRights fileSystemRights =
FileSystemRights.WriteData |
FileSystemRights.AppendData |
@ -1517,9 +1516,6 @@ namespace BuildXL.Native.IO.Windows
FileSystemRights.WriteExtendedAttributes;
return CheckFileSystemRightsForPath(path, fileSystemRights);
#else
return true;
#endif
}
@ -1529,15 +1525,11 @@ namespace BuildXL.Native.IO.Windows
Contract.Requires(!string.IsNullOrWhiteSpace(path));
path = FileSystemWin.ToLongPathIfExceedMaxPath(path);
#if NET_FRAMEWORK
FileSystemRights fileSystemRights =
FileSystemRights.WriteAttributes |
FileSystemRights.WriteExtendedAttributes;
return CheckFileSystemRightsForPath(path, fileSystemRights);
#else
return true;
#endif
}
private bool CheckFileSystemRightsForPath(string path, FileSystemRights fileSystemRights)

Просмотреть файл

@ -7,6 +7,7 @@ using System.Diagnostics;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;
using BuildXL.Cache.ContentStore.Interfaces.Extensions;
@ -999,6 +1000,24 @@ namespace Test.BuildXL.Storage
XAssert.IsFalse(FileUtilities.DirectoryExistsNoFollow(directorySymlinkPath));
}
[FactIfSupported(requiresWindowsBasedOperatingSystem: true)]
public void HasWritableAccessControlTest()
{
string testFilePath = Path.Combine(TemporaryDirectory, "testFile.txt");
File.WriteAllText(testFilePath, "hello");
XAssert.IsTrue(FileUtilities.HasWritableAccessControl(testFilePath));
XAssert.IsTrue(FileUtilities.HasWritableAttributeAccessControl(testFilePath));
FileUtilities.SetFileAccessControl(testFilePath, FileSystemRights.WriteData, false);
XAssert.IsTrue(FileUtilities.HasWritableAttributeAccessControl(testFilePath));
XAssert.IsFalse(FileUtilities.HasWritableAccessControl(testFilePath));
FileUtilities.SetFileAccessControl(testFilePath, FileSystemRights.WriteAttributes, false);
XAssert.IsFalse(FileUtilities.HasWritableAccessControl(testFilePath));
XAssert.IsFalse(FileUtilities.HasWritableAttributeAccessControl(testFilePath));
}
private void AssertNonexistent(Possible<PathExistence, NativeFailure> maybeFileExistence)
=> AssertPathExistence(PathExistence.Nonexistent, maybeFileExistence);

Просмотреть файл

@ -21,6 +21,7 @@ namespace Storage {
importFrom("BuildXL.Utilities").Storage.dll,
importFrom("BuildXL.Utilities.Instrumentation").Common.dll,
importFrom("BuildXL.Utilities").Collections.dll,
...importFrom("BuildXL.Utilities").Native.securityDlls,
],
runtimeContent: [
dummyWaiterExe