From b85e16127a7c099936cd1e56f3d6893d611999fe Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Mon, 7 Sep 2015 18:33:08 -0400 Subject: [PATCH] Add ~>> and ~>! operators for FKFileType --- FileKit/Core/FKOperators.swift | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/FileKit/Core/FKOperators.swift b/FileKit/Core/FKOperators.swift index 3a3a136..2ce864a 100644 --- a/FileKit/Core/FKOperators.swift +++ b/FileKit/Core/FKOperators.swift @@ -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 ~>> (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 @@ -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 ~>! (lhs: FileType, rhs: FKPath) throws { + if rhs.exists { + try rhs.deleteFile() + } + try lhs ~>> rhs +} + postfix operator • {} /// Returns the standardized version of the path.