33// Macro
44//
55// Created by Helge Hess.
6- // Copyright © 2020-2023 ZeeZide GmbH. All rights reserved.
6+ // Copyright © 2020-2026 ZeeZide GmbH. All rights reserved.
77//
88
99import protocol NIO. EventLoop
@@ -24,6 +24,7 @@ import struct xsys.mode_t
2424import let xsys. mkdir
2525import let xsys. rmdir
2626import var xsys. errno
27+ import let xsys. rename
2728
2829// Most, not all, funcs currently require Foundation and should be reimplemented
2930// using Posix as an alternative.
@@ -406,6 +407,67 @@ public struct MakeDirOptions: Equatable {
406407 }
407408}
408409
410+ // MARK: - Async Callback Variants
411+
412+ /**
413+ * Create a directory asynchronously on the thread pool (blocks).
414+ *
415+ * - Parameters:
416+ * - path: The path to the directory to create.
417+ * - options: The ``MakeDirOptions`` specifying the creation behaviour.
418+ * - yield: Called on completion with an optional error.
419+ */
420+ @inlinable
421+ public func mkdir( _ path: String ,
422+ _ options: MakeDirOptions = . init( ) ,
423+ yield: @escaping ( Error ? ) -> Void )
424+ {
425+ FileSystemModule . _evalAsync (
426+ mkdirSync, ( path, options) , yield)
427+ }
428+
429+ /**
430+ * Delete a directory asynchronously on the thread pool (blocks).
431+ *
432+ * - Parameters:
433+ * - path: The path to the directory to remove.
434+ * - yield: Called on completion with an optional error.
435+ */
436+ @inlinable
437+ public func rmdir( _ path: String , yield: @escaping ( Error ? ) -> Void ) {
438+ FileSystemModule . _evalAsync ( rmdirSync, path, yield)
439+ }
440+
441+ /**
442+ * Delete a file asynchronously on the thread pool (blocks).
443+ *
444+ * - Parameters:
445+ * - path: The path to the file to remove.
446+ * - yield: Called on completion with an optional error.
447+ */
448+ @inlinable
449+ public func unlink( _ path: String , yield: @escaping ( Error ? ) -> Void ) {
450+ FileSystemModule . _evalAsync ( unlinkSync, path, yield)
451+ }
452+
453+ /**
454+ * Rename a file or directory asynchronously on the thread pool (blocks).
455+ *
456+ * - Parameters:
457+ * - oldPath: The current path.
458+ * - newPath: The new path.
459+ * - yield: Called on completion with an optional error.
460+ */
461+ @inlinable
462+ public func rename( _ oldPath: String , _ newPath: String ,
463+ yield: @escaping ( Error ? ) -> Void )
464+ {
465+ FileSystemModule . _evalAsync ( renameSync, ( oldPath, newPath) , yield)
466+ }
467+
468+
469+ // MARK: - Sync Variants
470+
409471/**
410472 * Create a directory synchronously, on the active thread.
411473 *
@@ -443,7 +505,7 @@ public func mkdirSync(_ path: String, _ umask: String) throws {
443505}
444506
445507/**
446- * Delete a directory synchronously, on the active thread.
508+ * Delete a directory synchronously, on the active thread (blocks) .
447509 *
448510 * - Parameters:
449511 * - path: The path to the directory to create.
@@ -459,7 +521,7 @@ public func rmdirSync(_ path: String) throws {
459521}
460522
461523/**
462- * Delete a directory or file synchronously, on the active thread.
524+ * Delete a directory or file synchronously, on the active thread (blocks) .
463525 *
464526 * - Parameters:
465527 * - path: The path to the directory to create.
@@ -474,6 +536,18 @@ public func unlinkSync(_ path: String) throws {
474536 #endif
475537}
476538
539+ /**
540+ * Rename a file or directory synchronously, on the active thread (blocks).
541+ *
542+ * - Parameters:
543+ * - path: The path to rename
544+ * - newPath: The new name.
545+ */
546+ public func renameSync( _ path: String , _ newPath: String ) throws {
547+ let rc = rename ( path, newPath)
548+ if rc != 0 { try throwErrno ( ) }
549+ }
550+
477551/**
478552 * Throw a custom error for the currently active Posix `errno` value.
479553 */
0 commit comments