|
7 | 7 | // |
8 | 8 | #if !os(Windows) |
9 | 9 |
|
| 10 | +#if canImport(Android) |
| 11 | +import Android |
| 12 | +#endif |
| 13 | + |
10 | 14 | #if os(Android) && (arch(i386) || arch(arm)) // struct stat.st_mode is UInt32 |
11 | 15 | internal func &(left: UInt32, right: mode_t) -> mode_t { |
12 | 16 | return mode_t(left) & right |
@@ -351,7 +355,14 @@ extension FileManager { |
351 | 355 | defer { ps.deallocate() } |
352 | 356 | ps.initialize(to: UnsafeMutablePointer(mutating: fsRep)) |
353 | 357 | ps.advanced(by: 1).initialize(to: nil) |
354 | | - return fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR | FTS_NOSTAT, nil) |
| 358 | + return ps.withMemoryRebound(to: UnsafeMutablePointer<CChar>.self, capacity: 2) { rebound_ps in |
| 359 | +#if canImport(Android) |
| 360 | + let arg = rebound_ps |
| 361 | +#else |
| 362 | + let arg = ps |
| 363 | +#endif |
| 364 | + return fts_open(arg, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR | FTS_NOSTAT, nil) |
| 365 | + } |
355 | 366 | } |
356 | 367 | if _stream == nil { |
357 | 368 | throw _NSErrorWithErrno(errno, reading: true, url: url) |
@@ -398,13 +409,13 @@ extension FileManager { |
398 | 409 |
|
399 | 410 | _current = fts_read(stream) |
400 | 411 | while let current = _current { |
401 | | - let filename = FileManager.default.string(withFileSystemRepresentation: current.pointee.fts_path, length: Int(current.pointee.fts_pathlen)) |
| 412 | + let filename = FileManager.default.string(withFileSystemRepresentation: current.pointee.fts_path!, length: Int(current.pointee.fts_pathlen)) |
402 | 413 |
|
403 | 414 | switch Int32(current.pointee.fts_info) { |
404 | 415 | case FTS_D: |
405 | 416 | let (showFile, skipDescendants) = match(filename: filename, to: _options, isDir: true) |
406 | 417 | if skipDescendants { |
407 | | - fts_set(_stream, _current, FTS_SKIP) |
| 418 | + fts_set(stream, _current!, FTS_SKIP) |
408 | 419 | } |
409 | 420 | if showFile { |
410 | 421 | return URL(fileURLWithPath: filename, isDirectory: true) |
@@ -578,7 +589,7 @@ extension FileManager { |
578 | 589 | let finalErrno = originalItemURL.withUnsafeFileSystemRepresentation { (originalFS) -> Int32? in |
579 | 590 | return newItemURL.withUnsafeFileSystemRepresentation { (newItemFS) -> Int32? in |
580 | 591 | // This is an atomic operation in many OSes, but is not guaranteed to be atomic by the standard. |
581 | | - if rename(newItemFS, originalFS) == 0 { |
| 592 | + if rename(newItemFS!, originalFS!) == 0 { |
582 | 593 | return nil |
583 | 594 | } else { |
584 | 595 | return errno |
|
0 commit comments