Skip to content

Commit

Permalink
Support setting ACLs on file paths longer than MAX_PATH (#92460)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Sitnik <adam.sitnik@gmail.com>
  • Loading branch information
karakasa and adamsitnik authored Sep 22, 2023
1 parent fcb9ad9 commit 2f7276e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ internal void Persist(string fullPath)
try
{
AccessControlSections persistRules = GetAccessControlSectionsFromChanges();
base.Persist(fullPath, persistRules);
base.Persist(PathInternal.EnsureExtendedPrefixIfNeeded(fullPath), persistRules);
OwnerModified = GroupModified = AuditRulesModified = AccessRulesModified = false;
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,25 @@ public void SetAccessControl_FileInfo_FileSecurity_Success()
fileInfo.SetAccessControl(fileSecurity);
}

[Fact]
public void SetAccessControl_FileInfo_FileSecurity_Success_NameLongerThanMaxShortPath()
{
using var directory = new TempAclDirectory();

const int MaxShortPath = 260;
int fileNameLength = Math.Max(MaxShortPath - directory.Path.Length, 1);

string path = Path.Combine(directory.Path, new string('1', fileNameLength) + ".txt");
using var file = new TempFile(path, 1);
var fileInfo = new FileInfo(file.Path);
FileSecurity fileSecurity = fileInfo.GetAccessControl(AccessControlSections.Access);

var newAccessRule = new FileSystemAccessRule(Helpers.s_NetworkServiceNTAccount, FileSystemRights.Write, AccessControlType.Allow);
fileSecurity.SetAccessRule(newAccessRule);

fileInfo.SetAccessControl(fileSecurity);
}

[Fact]
public void SetAccessControl_FileStream_FileSecurity_InvalidArguments()
{
Expand Down

0 comments on commit 2f7276e

Please sign in to comment.