11
11
internal func & ( left: UInt32 , right: mode_t ) -> mode_t {
12
12
return mode_t ( left) & right
13
13
}
14
+ #elseif os(Android)
15
+ internal func & ( left: mode_t , right: Int32 ) -> mode_t {
16
+ return left & mode_t ( right)
17
+ }
14
18
#endif
15
19
16
20
#if os(WASI)
@@ -409,7 +413,7 @@ extension FileManager {
409
413
if !parent. isEmpty && !fileExists( atPath: parent, isDirectory: & isDir) {
410
414
try createDirectory ( atPath: parent, withIntermediateDirectories: true , attributes: attributes)
411
415
}
412
- if mkdir ( pathFsRep, S_IRWXU | S_IRWXG | S_IRWXO) != 0 {
416
+ if mkdir ( pathFsRep, mode_t ( S_IRWXU) | mode_t ( S_IRWXG) | mode_t ( S_IRWXO) ) != 0 {
413
417
let posixError = errno
414
418
if posixError == EEXIST && fileExists ( atPath: path, isDirectory: & isDir) && isDir. boolValue {
415
419
// Continue; if there is an existing file and it is a directory, that is still a success.
@@ -428,7 +432,7 @@ extension FileManager {
428
432
throw _NSErrorWithErrno ( EEXIST, reading: false , path: path)
429
433
}
430
434
} else {
431
- if mkdir ( pathFsRep, S_IRWXU | S_IRWXG | S_IRWXO) != 0 {
435
+ if mkdir ( pathFsRep, mode_t ( S_IRWXU) | mode_t ( S_IRWXG) | mode_t ( S_IRWXO) ) != 0 {
432
436
throw _NSErrorWithErrno ( errno, reading: false , path: path)
433
437
} else if let attr = attributes {
434
438
try self . setAttributes ( attr, ofItemAtPath: path)
@@ -803,29 +807,31 @@ extension FileManager {
803
807
let ps = UnsafeMutablePointer< UnsafeMutablePointer< Int8>?> . allocate( capacity: 2 )
804
808
ps. initialize ( to: UnsafeMutablePointer ( mutating: fsRep) )
805
809
ps. advanced ( by: 1 ) . initialize ( to: nil )
806
- let stream = fts_open ( ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR | FTS_NOSTAT, nil )
810
+ let stream = ps. withMemoryRebound ( to: UnsafeMutablePointer< CChar> . self , capacity: 2 ) {
811
+ fts_open ( $0, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR | FTS_NOSTAT, nil )
812
+ }
807
813
ps. deinitialize ( count: 2 )
808
814
ps. deallocate ( )
809
815
810
- if stream != nil {
816
+ if let stream {
811
817
defer {
812
818
fts_close ( stream)
813
819
}
814
820
815
- while let current = fts_read ( stream) ? . pointee {
816
- let itemPath = string ( withFileSystemRepresentation: current . fts_path, length: Int ( current. fts_pathlen) )
821
+ while let current = fts_read ( stream) ? . pointee, let fts_path = current . fts_path {
822
+ let itemPath = string ( withFileSystemRepresentation: fts_path, length: Int ( current. fts_pathlen) )
817
823
guard alreadyConfirmed || shouldRemoveItemAtPath ( itemPath, isURL: isURL) else {
818
824
continue
819
825
}
820
826
821
827
do {
822
828
switch Int32 ( current. fts_info) {
823
829
case FTS_DEFAULT, FTS_F, FTS_NSOK, FTS_SL, FTS_SLNONE:
824
- if unlink ( current . fts_path) == - 1 {
830
+ if unlink ( fts_path) == - 1 {
825
831
throw _NSErrorWithErrno ( errno, reading: false , path: itemPath)
826
832
}
827
833
case FTS_DP:
828
- if rmdir ( current . fts_path) == - 1 {
834
+ if rmdir ( fts_path) == - 1 {
829
835
throw _NSErrorWithErrno ( errno, reading: false , path: itemPath)
830
836
}
831
837
case FTS_DNR, FTS_ERR, FTS_NS:
@@ -1171,7 +1177,9 @@ extension FileManager {
1171
1177
defer { ps. deallocate ( ) }
1172
1178
ps. initialize ( to: UnsafeMutablePointer ( mutating: fsRep) )
1173
1179
ps. advanced ( by: 1 ) . initialize ( to: nil )
1174
- return fts_open ( ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR | FTS_NOSTAT, nil )
1180
+ return ps. withMemoryRebound ( to: UnsafeMutablePointer< CChar> . self , capacity: 2 ) {
1181
+ fts_open ( $0, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR | FTS_NOSTAT, nil )
1182
+ }
1175
1183
}
1176
1184
if _stream == nil {
1177
1185
throw _NSErrorWithErrno ( errno, reading: true , url: url)
@@ -1218,13 +1226,13 @@ extension FileManager {
1218
1226
1219
1227
_current = fts_read ( stream)
1220
1228
while let current = _current {
1221
- let filename = FileManager . default. string ( withFileSystemRepresentation: current. pointee. fts_path, length: Int ( current. pointee. fts_pathlen) )
1229
+ let filename = FileManager . default. string ( withFileSystemRepresentation: current. pointee. fts_path! , length: Int ( current. pointee. fts_pathlen) )
1222
1230
1223
1231
switch Int32 ( current. pointee. fts_info) {
1224
1232
case FTS_D:
1225
1233
let ( showFile, skipDescendants) = match ( filename: filename, to: _options, isDir: true )
1226
1234
if skipDescendants {
1227
- fts_set ( _stream , _current, FTS_SKIP)
1235
+ fts_set ( stream , _current! , FTS_SKIP)
1228
1236
}
1229
1237
if showFile {
1230
1238
return URL ( fileURLWithPath: filename, isDirectory: true )
@@ -1398,7 +1406,7 @@ extension FileManager {
1398
1406
let finalErrno = originalItemURL. withUnsafeFileSystemRepresentation { ( originalFS) -> Int32 ? in
1399
1407
return newItemURL. withUnsafeFileSystemRepresentation { ( newItemFS) -> Int32 ? in
1400
1408
// This is an atomic operation in many OSes, but is not guaranteed to be atomic by the standard.
1401
- if rename ( newItemFS, originalFS) == 0 {
1409
+ if rename ( newItemFS! , originalFS! ) == 0 {
1402
1410
return nil
1403
1411
} else {
1404
1412
return errno
0 commit comments