Skip to content

Commit 3ace3f7

Browse files
github-actions[bot]karakasaadamsitnik
authored
[release/8.0-staging] Support setting ACLs on file paths longer than MAX_PATH (#113801)
* fix long path bug * Simplify test with Math.Max Co-authored-by: Adam Sitnik <[email protected]> --------- Co-authored-by: Gan Keyu <[email protected]> Co-authored-by: Keyu Gan <[email protected]> Co-authored-by: Adam Sitnik <[email protected]>
1 parent cc4c5be commit 3ace3f7

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/libraries/System.IO.FileSystem.AccessControl/src/System/Security/AccessControl/FileSystemSecurity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ internal void Persist(string fullPath)
121121
try
122122
{
123123
AccessControlSections persistRules = GetAccessControlSectionsFromChanges();
124-
base.Persist(fullPath, persistRules);
124+
base.Persist(PathInternal.EnsureExtendedPrefixIfNeeded(fullPath), persistRules);
125125
OwnerModified = GroupModified = AuditRulesModified = AccessRulesModified = false;
126126
}
127127
finally

src/libraries/System.IO.FileSystem.AccessControl/tests/FileSystemAclExtensionsTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,25 @@ public void SetAccessControl_FileInfo_FileSecurity_Success()
143143
fileInfo.SetAccessControl(fileSecurity);
144144
}
145145

146+
[Fact]
147+
public void SetAccessControl_FileInfo_FileSecurity_Success_NameLongerThanMaxShortPath()
148+
{
149+
using var directory = new TempAclDirectory();
150+
151+
const int MaxShortPath = 260;
152+
int fileNameLength = Math.Max(MaxShortPath - directory.Path.Length, 1);
153+
154+
string path = Path.Combine(directory.Path, new string('1', fileNameLength) + ".txt");
155+
using var file = new TempFile(path, 1);
156+
var fileInfo = new FileInfo(file.Path);
157+
FileSecurity fileSecurity = fileInfo.GetAccessControl(AccessControlSections.Access);
158+
159+
var newAccessRule = new FileSystemAccessRule(Helpers.s_NetworkServiceNTAccount, FileSystemRights.Write, AccessControlType.Allow);
160+
fileSecurity.SetAccessRule(newAccessRule);
161+
162+
fileInfo.SetAccessControl(fileSecurity);
163+
}
164+
146165
[Fact]
147166
public void SetAccessControl_FileStream_FileSecurity_InvalidArguments()
148167
{

0 commit comments

Comments
 (0)