Skip to content

Implemented FileManager.delegate and cross-device move #1673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2018
Merged

Implemented FileManager.delegate and cross-device move #1673

merged 1 commit into from
Oct 26, 2018

Conversation

amosavian
Copy link
Contributor

@amosavian amosavian commented Aug 27, 2018

  • Added FileManager.delegate functionality
  • Updated FileManagerDelegate default implementation method signature to match protocol methods.
  • Fixed TODO: Implemented cross-device move in moveItem()
  • Fixed TODO: Error handling if fts_read fails in removeItem()

@amosavian
Copy link
Contributor Author

@parkera would you mind reviewing this PR?

@parkera parkera requested a review from kperryua August 29, 2018 20:50
}

@inline(__always)
func shouldMoveItemAtPath(_ path: String, toPath: String, isURL: Bool) -> Bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be fileprivate as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably be private since it is in the class and the @inline(__always) probably isn't required as the compiler can make that decision.

// TODO: Copy and delete.
NSUnimplemented("Cross-device moves not yet implemented")
try _copyOrLinkDirectoryHelper(atPath: srcPath, toPath: dstPath) { (srcPath, dstPath, fileType) in
guard shouldMoveItemAtPath(srcPath, toPath: dstPath, isURL: isURL) else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant with the initial shouldMoveItemAtPath check, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, for two reason:

  1. This body is called only when rename() fails
  2. This is called for every file for recursive copy/move

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, Darwin's implementation doesn't ask "should move" for every subitem when it falls back to a copy. The delegate-calling semantics of the operation is identical in either case. As such, the initial shouldMove check should be sufficient confirmation for either the rename or the recursive copy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I will chack again 🙏

while let current = fts_read(stream)?.pointee {


let itemPath = NSString(bytes: current.fts_path,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spevans Can I replace this with String.init(cString:)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best to use self.string(withFileSystemRepresentation:length:) to convert to a String.

@amosavian amosavian closed this Sep 1, 2018
@amosavian amosavian reopened this Sep 1, 2018
@amosavian
Copy link
Contributor Author

amosavian commented Sep 1, 2018

Changes:

  • Using string(withFileSystemRepresentation:length:) when possible
  • shouldMoveItemAtPath will be called only once for recursive operation
  • Adding "NSSourceFilePathErrorKey", "NSDestinationFilePath" and "NSUserStringVariant" keys to copy/move errors to match Darwin version
  • Rebased in order to resolve merge conflict

cc @kperryua @spevans

@spevans
Copy link
Contributor

spevans commented Sep 1, 2018

@swift-ci test

1 similar comment
@spevans
Copy link
Contributor

spevans commented Sep 2, 2018

@swift-ci test

@amosavian
Copy link
Contributor Author

Hi, is it normal to have a pull request open without and feedback/activity? @parkera

@kperryua
Copy link
Contributor

Apologies, that's my fault. I dropped the ball on following up after my previous feedback. I'll take another look at this today.

@amosavian
Copy link
Contributor Author

@kperryua pardon me for disturbing. But it’s hard to keep unmerged PRs synchronized.

Copy link
Contributor

@kperryua kperryua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Looks good to me.

@amosavian
Copy link
Contributor Author

@parkera pardon me for disturbing you repeatedly. Would you mind review this PR?

@parkera
Copy link
Contributor

parkera commented Oct 25, 2018

If @kperryua approves that's as good as my approval.

@amosavian
Copy link
Contributor Author

They approved as I see.

@spevans
Copy link
Contributor

spevans commented Oct 26, 2018

@swift-ci test and merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants