oceanbit / GitShark

🦈 A Git client to surf through your repos on mobile
https://gitshark.dev
Mozilla Public License 2.0
136 stars 9 forks source link

Get iOS Clone Working #53

Closed crutchcorn closed 3 years ago

crutchcorn commented 4 years ago

Currently, even on the ios-directory-picker branch, I'm unable to clone due to FS access issues.

image

This is because we're trying to export our files to a new directory:

 let documentPicker =
          UIDocumentPickerViewController(documentTypes: [kUTTypeFolder as String],
                                         in: .open)
          documentPicker.delegate = self
      self.topMostViewController()?.present(documentPicker, animated: true, completion: nil)

However, Apple Docs make it clear that you must "request access" every time you want to read or write a file.

Further, we'd like to see if we're able to use SwiftGit2 bindings in order to do the clone action on iOS. So, we're going to be doing the following steps, in order, and returning the results here:

My suspicion warns me that the "lock/unlock" pattern won't actually work, but boy it would be grand if it did

crutchcorn commented 4 years ago

I'm literally getting stuck on the first part of this 😅

When trying to run the following:

@objc(createFolder:folderName:)
  public func createFolder(_ path: String, folderName: String) {
    let url = URL(fileURLWithPath: path);
    guard url.startAccessingSecurityScopedResource() else {
        print("THERE WAS A FAILURE HERE")
        return
    }

    defer { url.stopAccessingSecurityScopedResource() }

    let fileManager = FileManager.default
    let filePath =  url.appendingPathComponent("\(folderName)")
    do {
      try fileManager.createDirectory(atPath: filePath.path, withIntermediateDirectories: true, attributes: nil)
    } catch {
      print(error.localizedDescription)
    }
  }

From JS:

NativeModules.DirectoryPicker.pickFolder().then((val: string[]) => {
     NativeModules.DirectoryPicker.createFolder(val[0], 'test2');
});

I'm hitting the THERE WAS A FAILURE HERE message, indicating that my read/write permission to use this folder has been denied

crutchcorn commented 3 years ago

Fixed via 18543d87339269997ff4d663d6a96028a27c0a4f