Last active
October 22, 2024 23:18
-
-
Save krzyzanowskim/61fc00e64875b1f1c81c9ef5255fad4a to your computer and use it in GitHub Desktop.
Filewrapper does not reread (refresh) its content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
let dirURL = URL(filePath: "/Users/marcinkrzyzanowski/Downloads/filewrappertest.test") | |
// cleanup | |
try? FileManager.default.removeItem(at: URL(filePath: "/Users/marcinkrzyzanowski/Downloads/filewrappertest.test/COPY.png")) | |
let fw = try FileWrapper(url: dirURL) | |
// fw.fileWrappers // ["IMG_0736.png": <NSFileWrapper: 0x6000023a8420>] | |
// add item (copy new item into directory | |
try FileManager.default.copyItem(at: URL(filePath: "/Users/marcinkrzyzanowski/Downloads/filewrappertest.test/IMG_0736.png"), to: URL(filePath: "/Users/marcinkrzyzanowski/Downloads/filewrappertest.test/COPY.png")) | |
// Force update parent directory attribute fixes the matchesContents(of:) | |
// try FileManager().setAttributes([.modificationDate: Date.now.addingTimeInterval(2)], ofItemAtPath: dirURL.path()) | |
fw.fileWrappers! // ["IMG_0736.png": <NSFileWrapper: 0x6000023a8420>] | |
fw.matchesContents(of: dirURL) // true (!!!!!!) | |
// read, like in "refresh" | |
// Recursively rereads the entire contents of a file wrapper from the specified location on disk. | |
try fw.read(from: dirURL) | |
// https://developer.apple.com/documentation/foundation/filewrapper/1408360-matchescontents | |
// Indicates whether the contents of a file wrapper matches a directory, regular file, or symbolic link on disk. | |
// For a directory, children are compared against the files in the directory, recursively. | |
fw.matchesContents(of: dirURL) // true! but the content is different | |
fw.fileWrappers! // ["COPY.png": <NSFileWrapper: 0x600003454a20>, "IMG_0736.png": <NSFileWrapper: 0x6000023a8420>] | |
Author
krzyzanowskim
commented
Oct 22, 2024
•
the other time, copyItem does not update parent directory
// add item (copy new item into directory `modificationDate`
try FileManager.default.copyItem(at: URL(filePath: "/Users/marcinkrzyzanowski/Downloads/filewrappertest.test/IMG_0736.png"), to: URL(filePath: "/Users/marcinkrzyzanowski/Downloads/filewrappertest.test/COPY.png"))
all of all it is about make sure attributes change or matchesContents(of:)
not going to recognize any change
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment