Skip to content

Commit

Permalink
Add ~>> and ~>! operators for FKFileType
Browse files Browse the repository at this point in the history
  • Loading branch information
nvzqz committed Sep 7, 2015
1 parent 9faf465 commit b85e161
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions FileKit/Core/FKOperators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,20 @@ public func ~>> (lhs: FKPath, rhs: FKPath) throws {
try lhs.createSymlinkToPath(rhs)
}

/// Symlinks a file to a path.
///
/// If the path already exists and _is not_ a directory, an error will be
/// thrown and a link will not be created.
///
/// If the path already exists and _is_ a directory, the link will be made
/// to the file in that directory.
///
/// - Throws: `FKError.FileDoesNotExist`, `FKError.CreateSymlinkFail`
///
public func ~>> <FileType: FKFileType>(lhs: FileType, rhs: FKPath) throws {
try lhs.symlinkToPath(rhs)
}

infix operator ~>! {}

/// Forcibly creates a symlink of the left path at the right path by deleting
Expand All @@ -249,6 +263,23 @@ public func ~>! (lhs: FKPath, rhs: FKPath) throws {
try lhs ~>> rhs
}

/// Forcibly creates a symlink of a file at a path by deleting anything at the
/// path before creating the symlink.
///
/// - Warning: If the path already exists, it will be deleted.
///
/// - Throws:
/// - `FKError.DeleteFileFail`,
/// - `FKError.FileDoesNotExist`,
/// - `FKError.CreateSymlinkFail`
///
public func ~>! <FileType: FKFileType>(lhs: FileType, rhs: FKPath) throws {
if rhs.exists {
try rhs.deleteFile()
}
try lhs ~>> rhs
}

postfix operator {}

/// Returns the standardized version of the path.
Expand Down

0 comments on commit b85e161

Please sign in to comment.