@@ -520,13 +520,14 @@ enum _FileOperations {
520
520
throw CocoaError . removeFileError ( err, errPath)
521
521
522
522
case let . entry( entry) :
523
+ let fts_path = entry. ftsEnt. fts_path!
523
524
switch Int32 ( entry. ftsEnt. fts_info) {
524
525
case FTS_DEFAULT, FTS_F, FTS_NSOK, FTS_SL, FTS_SLNONE:
525
- let currentPathStr = resolve ( path: String ( cString: entry . ftsEnt . fts_path) )
526
+ let currentPathStr = resolve ( path: String ( cString: fts_path) )
526
527
guard fileManager? . _shouldRemoveItemAtPath ( currentPathStr) ?? true else {
527
528
break
528
529
}
529
- if unlink ( entry . ftsEnt . fts_path) != 0 {
530
+ if unlink ( fts_path) != 0 {
530
531
let error = CocoaError . removeFileError ( errno, currentPathStr)
531
532
if !( fileManager? . _shouldProceedAfter ( error: error, removingItemAtPath: currentPathStr) ?? false ) {
532
533
throw error
@@ -538,20 +539,20 @@ enum _FileOperations {
538
539
isFirst = false
539
540
break
540
541
}
541
- let currentPathStr = resolve ( path: String ( cString: entry . ftsEnt . fts_path) )
542
+ let currentPathStr = resolve ( path: String ( cString: fts_path) )
542
543
if !( fileManager? . _shouldRemoveItemAtPath ( currentPathStr) ?? true ) {
543
544
iterator. skipDescendants ( of: entry, skipPostProcessing: true )
544
545
}
545
546
case FTS_DP:
546
- if rmdir ( entry . ftsEnt . fts_path) != 0 {
547
- let currentPathStr = resolve ( path: String ( cString: entry . ftsEnt . fts_path) )
547
+ if rmdir ( fts_path) != 0 {
548
+ let currentPathStr = resolve ( path: String ( cString: fts_path) )
548
549
let error = CocoaError . removeFileError ( errno, currentPathStr)
549
550
if !( fileManager? . _shouldProceedAfter ( error: error, removingItemAtPath: currentPathStr) ?? false ) {
550
551
throw error
551
552
}
552
553
}
553
554
case FTS_DNR, FTS_ERR, FTS_NS:
554
- let currentPathStr = resolve ( path: String ( cString: entry . ftsEnt . fts_path) )
555
+ let currentPathStr = resolve ( path: String ( cString: fts_path) )
555
556
throw CocoaError . removeFileError ( entry. ftsEnt. fts_errno, currentPathStr)
556
557
default :
557
558
break
@@ -866,12 +867,12 @@ enum _FileOperations {
866
867
return
867
868
}
868
869
869
- let total = fileInfo. st_size
870
- let chunkSize = Int ( fileInfo. st_blksize)
871
- var current = 0
870
+ let total : Int = Int ( fileInfo. st_size)
871
+ let chunkSize : Int = Int ( fileInfo. st_blksize)
872
+ var current : off_t = 0
872
873
873
874
while current < total {
874
- guard sendfile ( dstfd, srcfd, & current, Swift . min ( total - current, chunkSize) ) != - 1 else {
875
+ guard sendfile ( dstfd, srcfd, & current, Swift . min ( total - Int ( current) , chunkSize) ) != - 1 else {
875
876
try delegate. throwIfNecessary ( errno, String ( cString: srcPtr) , String ( cString: dstPtr) )
876
877
return
877
878
}
@@ -894,11 +895,12 @@ enum _FileOperations {
894
895
throw CocoaError . errorWithFilePath ( path, errno: errno, reading: true )
895
896
896
897
case let . entry( entry) :
897
- let trimmedPathPtr = entry. ftsEnt. fts_path. advanced ( by: srcLen)
898
+ let fts_path = entry. ftsEnt. fts_path!
899
+ let trimmedPathPtr = fts_path. advanced ( by: srcLen)
898
900
Platform . copyCString ( dst: dstAppendPtr, src: trimmedPathPtr, size: remainingBuffer)
899
901
900
902
// we don't want to ask the delegate on the way back -up- the hierarchy if they want to copy a directory they've already seen and therefore already said "YES" to.
901
- guard entry. ftsEnt. fts_info == FTS_DP || delegate. shouldPerformOnItemAtPath ( String ( cString: entry . ftsEnt . fts_path) , to: String ( cString: buffer. baseAddress!) ) else {
903
+ guard entry. ftsEnt. fts_info == FTS_DP || delegate. shouldPerformOnItemAtPath ( String ( cString: fts_path) , to: String ( cString: buffer. baseAddress!) ) else {
902
904
if entry. ftsEnt. fts_info == FTS_D {
903
905
iterator. skipDescendants ( of: entry, skipPostProcessing: true )
904
906
}
@@ -911,29 +913,29 @@ enum _FileOperations {
911
913
case FTS_D:
912
914
// Directory being visited in pre-order - create it with whatever default perms will be on the destination.
913
915
#if canImport(Darwin)
914
- if copyfile ( entry . ftsEnt . fts_path, buffer. baseAddress!, nil , copyfile_flags_t ( COPYFILE_DATA | COPYFILE_EXCL | COPYFILE_NOFOLLOW | extraFlags) ) != 0 {
915
- try delegate. throwIfNecessary ( errno, String ( cString: entry . ftsEnt . fts_path) , String ( cString: buffer. baseAddress!) )
916
+ if copyfile ( fts_path, buffer. baseAddress!, nil , copyfile_flags_t ( COPYFILE_DATA | COPYFILE_EXCL | COPYFILE_NOFOLLOW | extraFlags) ) != 0 {
917
+ try delegate. throwIfNecessary ( errno, String ( cString: fts_path) , String ( cString: buffer. baseAddress!) )
916
918
}
917
919
#else
918
920
do {
919
921
try fileManager. createDirectory ( atPath: String ( cString: buffer. baseAddress!) , withIntermediateDirectories: true )
920
922
} catch {
921
- try delegate. throwIfNecessary ( error, String ( cString: entry . ftsEnt . fts_path) , String ( cString: buffer. baseAddress!) )
923
+ try delegate. throwIfNecessary ( error, String ( cString: fts_path) , String ( cString: buffer. baseAddress!) )
922
924
}
923
925
#endif
924
926
925
927
case FTS_DP:
926
928
// Directory being visited in post-order - copy the permissions over.
927
929
#if canImport(Darwin)
928
- if copyfile ( entry . ftsEnt . fts_path, buffer. baseAddress!, nil , copyfile_flags_t ( COPYFILE_METADATA | COPYFILE_NOFOLLOW | extraFlags) ) != 0 {
929
- try delegate. throwIfNecessary ( errno, String ( cString: entry . ftsEnt . fts_path) , String ( cString: buffer. baseAddress!) )
930
+ if copyfile ( fts_path, buffer. baseAddress!, nil , copyfile_flags_t ( COPYFILE_METADATA | COPYFILE_NOFOLLOW | extraFlags) ) != 0 {
931
+ try delegate. throwIfNecessary ( errno, String ( cString: fts_path) , String ( cString: buffer. baseAddress!) )
930
932
}
931
933
#else
932
934
do {
933
- let attributes = try fileManager. attributesOfItem ( atPath: String ( cString: entry . ftsEnt . fts_path) )
935
+ let attributes = try fileManager. attributesOfItem ( atPath: String ( cString: fts_path) )
934
936
try fileManager. setAttributes ( attributes, ofItemAtPath: String ( cString: buffer. baseAddress!) )
935
937
} catch {
936
- try delegate. throwIfNecessary ( error, String ( cString: entry . ftsEnt . fts_path) , String ( cString: buffer. baseAddress!) )
938
+ try delegate. throwIfNecessary ( error, String ( cString: fts_path) , String ( cString: buffer. baseAddress!) )
937
939
}
938
940
#endif
939
941
@@ -947,42 +949,42 @@ enum _FileOperations {
947
949
} else {
948
950
flags = COPYFILE_DATA | COPYFILE_METADATA | COPYFILE_EXCL | COPYFILE_NOFOLLOW | extraFlags
949
951
}
950
- if copyfile ( entry . ftsEnt . fts_path, buffer. baseAddress!, nil , copyfile_flags_t ( flags) ) != 0 {
951
- try delegate. throwIfNecessary ( errno, String ( cString: entry . ftsEnt . fts_path) , String ( cString: buffer. baseAddress!) )
952
+ if copyfile ( fts_path, buffer. baseAddress!, nil , copyfile_flags_t ( flags) ) != 0 {
953
+ try delegate. throwIfNecessary ( errno, String ( cString: fts_path) , String ( cString: buffer. baseAddress!) )
952
954
}
953
955
#else
954
956
try withUnsafeTemporaryAllocation ( of: CChar . self, capacity: FileManager . MAX_PATH_SIZE) { tempBuff in
955
957
tempBuff. initialize ( repeating: 0 )
956
958
defer { tempBuff. deinitialize ( ) }
957
- let len = readlink ( entry . ftsEnt . fts_path, tempBuff. baseAddress!, FileManager . MAX_PATH_SIZE - 1 )
959
+ let len = readlink ( fts_path, tempBuff. baseAddress!, FileManager . MAX_PATH_SIZE - 1 )
958
960
if len >= 0 , symlink ( tempBuff. baseAddress!, buffer. baseAddress!) != - 1 {
959
961
return
960
962
}
961
- try delegate. throwIfNecessary ( errno, String ( cString: entry . ftsEnt . fts_path) , String ( cString: buffer. baseAddress!) )
963
+ try delegate. throwIfNecessary ( errno, String ( cString: fts_path) , String ( cString: buffer. baseAddress!) )
962
964
}
963
965
#endif
964
966
965
967
case FTS_DEFAULT: fallthrough // Something not defined anywhere else.
966
968
case FTS_F: // Regular file.
967
969
if delegate. copyData {
968
970
#if canImport(Darwin)
969
- if copyfile ( entry . ftsEnt . fts_path, buffer. baseAddress!, nil , copyfile_flags_t ( COPYFILE_CLONE | COPYFILE_ALL | COPYFILE_EXCL | COPYFILE_NOFOLLOW | extraFlags) ) != 0 {
970
- try delegate. throwIfNecessary ( errno, String ( cString: entry . ftsEnt . fts_path) , String ( cString: buffer. baseAddress!) )
971
+ if copyfile ( fts_path, buffer. baseAddress!, nil , copyfile_flags_t ( COPYFILE_CLONE | COPYFILE_ALL | COPYFILE_EXCL | COPYFILE_NOFOLLOW | extraFlags) ) != 0 {
972
+ try delegate. throwIfNecessary ( errno, String ( cString: fts_path) , String ( cString: buffer. baseAddress!) )
971
973
}
972
974
#else
973
- try Self . _copyRegularFile ( entry . ftsEnt . fts_path, buffer. baseAddress!, delegate: delegate)
975
+ try Self . _copyRegularFile ( fts_path, buffer. baseAddress!, delegate: delegate)
974
976
#endif
975
977
} else {
976
- if link ( entry . ftsEnt . fts_path, buffer. baseAddress!) != 0 {
977
- try delegate. throwIfNecessary ( errno, String ( cString: entry . ftsEnt . fts_path) , String ( cString: buffer. baseAddress!) )
978
+ if link ( fts_path, buffer. baseAddress!) != 0 {
979
+ try delegate. throwIfNecessary ( errno, String ( cString: fts_path) , String ( cString: buffer. baseAddress!) )
978
980
}
979
981
}
980
982
981
983
// Error returns
982
984
case FTS_DNR: fallthrough // Directory cannot be read.
983
985
case FTS_ERR: fallthrough // Some error occurred, but we don't know what.
984
986
case FTS_NS: // No stat(2) information is available.
985
- try delegate. throwIfNecessary ( entry. ftsEnt. fts_errno, String ( cString: entry . ftsEnt . fts_path) , String ( cString: buffer. baseAddress!) )
987
+ try delegate. throwIfNecessary ( entry. ftsEnt. fts_errno, String ( cString: fts_path) , String ( cString: buffer. baseAddress!) )
986
988
987
989
default : break
988
990
}
0 commit comments