Skip to content

Commit

Permalink
feature(FileLinkManager.swift) implement hard link menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ololx committed Sep 2, 2021
1 parent 19f9767 commit 17d6d02
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions commons/link/FileLinkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Foundation
import FinderSync

public protocol FileLinkManager {

Expand Down Expand Up @@ -65,8 +66,13 @@ public class SoftLinkManager: FileLinkManager {
public class HardLinkManager: FileLinkManager {

public func linkWith(of: URL!, with: URL!) {

let pasteboard = NSPasteboard.general;
pasteboard.declareTypes([NSPasteboard.PasteboardType.string], owner: nil);

do {
try FileManager.default.createSymbolicLink(at: with!, withDestinationURL: ResourcePath.of(url: of).relativize(to: ResourcePath.of(url: with?.deletingLastPathComponent())).toUrl()!);
try FileManager.default.linkItem(at: of, to: with);

} catch let error as NSError {
NSLog("FileManager.createSymbolicLink() failed to create file: %@", error.description as NSString);
}
Expand All @@ -75,7 +81,7 @@ public class HardLinkManager: FileLinkManager {
public func replaceWith(of: URL!, with: URL!) {
do {
try FileManager.default.moveItem(at: of, to: with);
try FileManager.default.linkItem(at: with, to: ResourcePath.of(url: of).relativize(to: ResourcePath.of(url: with.deletingLastPathComponent())).toUrl()!);
try FileManager.default.linkItem(at: with, to: of);
} catch let error as NSError {
NSLog("FileManager.createSymbolicLink() failed to create file: %@", error.description as NSString);
}
Expand Down

0 comments on commit 17d6d02

Please sign in to comment.