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