File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed
Sources/FoundationEssentials/String
Tests/FoundationEssentialsTests/FileManager Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -361,19 +361,18 @@ extension String {
361
361
return nil
362
362
}
363
363
364
+ let length = Int ( buffer. fullPathAttr. attr_length) // Includes null byte
364
365
return withUnsafePointer ( to: buffer. fullPathBuf) { pathPtr in
365
- let start = UnsafeRawPointer ( pathPtr) . advanced ( by: Int ( buffer. fullPathAttr. attr_dataoffset) )
366
- let length = Int ( buffer. fullPathAttr. attr_length) // Includes null byte
367
- return start. withMemoryRebound ( to: CChar . self, capacity: length) { ccharPtr in
368
- return String ( cString: ccharPtr)
366
+ pathPtr. withMemoryRebound ( to: CChar . self, capacity: length) { ccharPtr in
367
+ String ( cString: ccharPtr)
369
368
}
370
369
}
371
370
#else
372
371
return nil
373
372
#endif
374
373
}
375
374
376
- private func _resolvingSymlinksInPath( ) -> String ? {
375
+ func _resolvingSymlinksInPath( ) -> String ? {
377
376
guard !isEmpty else { return nil }
378
377
return self . withFileSystemRepresentation { fsPtr -> String ? in
379
378
guard let fsPtr else { return nil }
Original file line number Diff line number Diff line change @@ -566,4 +566,15 @@ final class FileManagerTests : XCTestCase {
566
566
throw XCTSkip ( " This test is not applicable to this platform " )
567
567
#endif
568
568
}
569
+
570
+ func testResolveSymlinksViaGetAttrList( ) throws {
571
+ try FileManagerPlayground {
572
+ " destination "
573
+ } . test {
574
+ try $0. createSymbolicLink ( atPath: " link " , withDestinationPath: " destination " )
575
+ let absolutePath = $0. currentDirectoryPath. appendingPathComponent ( " link " )
576
+ let resolved = absolutePath. _resolvingSymlinksInPath ( ) // Call internal function to avoid path standardization
577
+ XCTAssertEqual ( resolved, $0. currentDirectoryPath. appendingPathComponent ( " destination " ) )
578
+ }
579
+ }
569
580
}
You can’t perform that action at this time.
0 commit comments