Files and Storage

RSS for tag

Ask questions about file systems and block storage.

Pinned Posts

Posts under Files and Storage tag

170 Posts
Sort by:
Post not yet marked as solved
0 Replies
56 Views
This documentation: Documentation/Bundle/Resources/Information Property List/Data and storage/NSSupportsPurgeableLocalStorage says: Property List Key NSSupportsPurgeableLocalStorage A Boolean value indicating whether the app continues working if the system purges the local storage. Under what conditions does the system "[purge] the local storage", and does this mean the entire local storage for the app? I can see how when a user deletes an app the local storage would be deleted, but then the app would not continue working, since it's no longer on the device.
Posted
by
Post marked as solved
4 Replies
105 Views
Hi, I'm trying to lock a file from objective-c (or plain C) so that other processes cannot read or write to it. So far, unsuccessfully. I've tried to use all APIs I can think of, but none locked the file: open then flock open then lockf open with O_EXLOCK open then fcntl (F_SETLK) open then NSDistributedLock I'm running macOS 11.6.1 on an APFS drive. For every API used, I was able to open and edit the file from command line using vi or just using cat on the file. Isn't there any way of preventing another process from accessing a file, until I'm done with it (ie. I closed the file, or the file handle is relinquished)? Thanks, Chris
Post not yet marked as solved
3 Replies
94 Views
Has anyone else seen in Ventura B3 where you have a URL path as a source and you want to use the filename for that, aka lastPathComponent in a destination URL, so you have something like: let destinationURL = destinationDIrectory.appendingPathExtension(sourceURL.lastPathComponent) and lastPathComponent is a file name but what you get for destinationURL is: destinationDirectory.lastPathComponent instead of destinationDirectory/lastPathComponent or is it just me?
Posted
by
Post not yet marked as solved
0 Replies
59 Views
I believe that if I rename a file, I'm supposed to do that inside a coordinated write on the parent directory - right? So say I have a file /path/to/folder/f1 and I want to rename it (in the same directory) as /path/to/folder/f2. I do a coordinated write (with the forMoving option) on the directory /path/to/folder. That passes me a possibly different path to the directory, right? Say I get /path/to/different. Question: what rename should I actually do? Do I need to construct from and to paths based on the different path that is passed to the accessor? I.e. do I rename from /path/to/folder/f1 to /path/to/folder/f2 or rename from /path/to/different/f1 to /path/to/different/f2 or some other combination? Do NSFileManager's renaming methods do anything special in this regard? Can I use e.g. std::filesystem::rename()? I am interested in both local documents that are visible e.g. in the Files app, and iCloud Drive documents, if that makes any difference. Thanks!
Posted
by
Post not yet marked as solved
3 Replies
154 Views
Hello! Does anyone maintain local virtual servers with local domain names and SSL security? If so please read on. I use OPENSSL@3 installed by Homebrew in a MacOS Monterey environment with Xcode working in the background to create a series of keys and certificates (see below) so that I can open my local sites with the https:// prefix. For several days, sometimes a week, or even more everything works fine. I can type in addresses such as localhost/index.html.en, ali.ourseventh.local, etc. in any browser window (Firefox, Safari, Chrome, etc.), and after an initial browser objection, my local servers open as if they were labeled with the .org, .net., .com extensions on the WAN. This can go on for days, with daily reboots. And then, out of nowhere, I wake up one morning, start my computer, and discover that I can no longer access my locally installed virtually hosted websites. As it takes many, many minutes to recreate and reinstall all of my certificates, and I never no when it is going to happen, it can become extremely frustrating -- especially when I am very busy. In crude outline things work as follows: In the folder /usr/local/etc/openssl@3/certs/ I create a number of files with the following names and extensions localhost.crt localhost.csr localhost.key reg.cnf myCA.pem myCA.key I save one of the above certificates in my keychain. Enter the command " brew services restart httpd " in terminal Open any browser and everything works fine, and voilà! Everything works fine. Can you offer any suggestions as to what is interfering and how to correct for it? Roddy
Posted
by
Post not yet marked as solved
0 Replies
79 Views
I am trying to create an app that downloads files and stores these files in the document folder that can be seen inside the Files App. I added these to the Info.plist file <key>UIFileSharingEnabled</key> <true/> <key>LSSupportsOpeningDocumentsInPlace</key> <true/> I also added debugging code to test that the file is indeed inside the document folder. The code can see the file, but the Files app doesn't show my app document's folder by itself (not even after adding files manually). There is a special case that does show my app folder inside the Files app: when I move an existing file I have to my app document folder. That is the only way that the Files app shows my app document folder - but the strange part is that still it doesn't show the file I downloaded inside (only the file I moved manually). Also: I tested on the simulator using iPhone 12 Pro and on a real device: same result. I deleted and re-installed the app many times, and also restarted Xcode and restarted the real device - nothing changed. This is the code that downloads the file into my app document folder. func downloadFile(urlString: String, filename: String, completionHandler: @escaping (_ err: Error?) -> Void) {     let config = URLSessionConfiguration.default           guard let url = URL(string: urlString), let documentPathURL = getDestFileURL() else { return }           let request = URLRequest(url: url)     let session = URLSession(configuration: config)           os_log("getting download folder %{public}@", documentPathURL.path as CVarArg)     let fileManager = FileManager()     let task = session.downloadTask(with: request) { url, response, error in       if error != nil {         os_log("error: %{public}@", error! as CVarArg)         completionHandler(error)         return       }       guard let fileURL = url else { return }       let fileNameParts = filename.components(separatedBy: ".")        do {         var isDir:ObjCBool = true         // download folder exists?         if !FileManager.default.fileExists(atPath: documentPathURL.path, isDirectory: &isDir) {           os_log("creating new folder")           try FileManager.default.createDirectory(atPath: documentPathURL.path, withIntermediateDirectories: true, attributes: nil)         }         let savePathURL = documentPathURL.appendingPathComponent(fileNameParts[0]).appendingPathExtension(fileNameParts[1])         // dest file exists?         if FileManager.default.fileExists(atPath: savePathURL.path) {           os_log("removing existing file")           try FileManager.default.removeItem(atPath: savePathURL.path)         }         // all good? then move the file!         try fileManager.moveItem(at: fileURL, to: savePathURL)         os_log("from path %{public}@", fileURL.path)         os_log("to path: %{public}@", savePathURL.path)         // dest file exists?         if FileManager.default.fileExists(atPath: savePathURL.path) {           let files = try fileManager.contentsOfDirectory(atPath: documentPathURL.path)           try fileManager.setAttributes([FileAttributeKey.protectionKey : FileProtectionType.none, FileAttributeKey.posixPermissions: 0o777], ofItemAtPath: savePathURL.path)           let attrs = try fileManager.attributesOfItem(atPath: savePathURL.path)           os_log("list of files %{public}@", files as CVarArg)           os_log("attrs of file %{public}@", attrs as CVarArg)           os_log("move was a success")         }                   completionHandler(nil)       }       catch {         os_log("final error: %{public}@", error as CVarArg)         completionHandler(MyError.couldNotDownload)       } } Can anyone see something wrong or missing? Thanks
Posted
by
Post marked as solved
1 Replies
65 Views
I've completed a simple app that plays 3D video. Now, I'm trying to make it open files from the menu, as well as using the Cmd-O keyboard shortcut. But the "Open" menu item in the "File" menu is gray - I don't know exactly what this means, but it seems that the current form of the app doesn't support openning files. I've had a func application(_ application: NSApplication, openFile filename: String) -> Bool function in my app delegate, I've had a CFBundleDocumentTypes with an entry of the MIME type of "video/mp4". What am I doing wrong?
Posted
by
Post not yet marked as solved
0 Replies
103 Views
Hello, Recently we added a change in our app that changed the resource addition to Photos - Until now we called addResourceWithType:fileURL:options: with PHAssetResourceCreationOptions.shouldMoveFile set to YES, and when we changed it to NO (the default value) we observed much more asset creation failures. Specifically we see a new error code in the procedure - PHPhotosErrorNotEnoughSpace. One can clearly see a connection between adding more storage to the file system and an asset creation failure that is related to storage, but we are struggling to understand a few things: The storage of the device is always higher than the video size, usually by a great amount - We observed failures for devices with 120GB free storage, while the video size was 200MB. Generally we save quite a lot of resources to the file system, so it is quite surprising to see supposedly storage issues when adding a relatively low amount of extra storage. The asset creation is part of a bigger procedure of encoding a video to a file system, and then moving/copying it to Photos. Is it that big of a difference to copy a video of 100MB-200MB instead of moving it, such that the overall procedure failure will increase drastically? Appreciate any help.
Posted
by
Post not yet marked as solved
0 Replies
72 Views
Dear Experts, NSCoordinatedFile's coordinatedRead and coordinatedWrite methods supply a possibly-modified path to the accessor block. (I think it is only modified if there are concurrent accesses, so none of this is easy to test.) If I enumerate the contents of a directory inside a coordinatedRead on the directory, the paths that I get for the directory entries will include this possibly-modified parent path. (Unless maybe NSFileManager's enumeration methods have some magic to avoid that.) Is it OK for me to keep these "special" pathnames beyond the end of the coordinatedRead? If not, perhaps I need to get only the leafname from the directory enumeration and append that to the original directory path. Thoughts anyone?
Posted
by
Post not yet marked as solved
1 Replies
85 Views
Hello there , i am new to apple developing and I was wondering if there’s a native api or some way to access your iMessage chat history and maybe get it in Jason or xml format?
Posted
by
Post not yet marked as solved
0 Replies
68 Views
Dear All, Does anyone have any suggestions for an iPad text editor app that is well-behaved with respect to NSFileCoordinator / NSFilePresenter / UIDocument etc.? Specifically, I'd like something that I can run in iPad split screen mode alongside my test app. I'd like to be able to make changes to files using the text editor and see my test app pick them up, and vice-versa. I am currently trying an app called "Quick Text" which mostly works but it doesn't seem to pick up changes that I make in my test app unless I close and re-open the file at its end. I'm also soon going to reach its limit of "10 edits per week"! I have a couple of others to try, but maybe someone here has a suggestion?
Posted
by
Post not yet marked as solved
0 Replies
84 Views
Dear Experts, Should I use NSFileCoordinator coordinateWritingItemAtURL: around a call to NSFileManager trashItemAtURL: ? What options should I pass - NSFileCoordinatorWritingForDeleting, or ...ForMoving, or something else? I've attempted various combinations. If I don't use the NSFileCoordinator, then the change is not reflected in the Files app (open alongside my test app in iPad split screen mode). All attempts using NSFileCoordinator result in a deadlock inside trashItemAtURL - it is stuck waiting for a semaphore. I do have a FilePresenter for this file, but I am passing it to the NSFileCoordinator's init so that should not lead to deadlock. I believe I am doing everything on the main thread. The files are local, in the app's Documents directory. Any ideas anyone?
Posted
by
Post not yet marked as solved
0 Replies
68 Views
Dear Experts, We are required to remove our NSFilePresenters from the NSFileCoordinator when the app goes to the background and re-add them when it returns to the foreground. Does this mean that when we foreground, we need to manually check if our files have been modified, deleted, or moved in the meantime? Or is there some mechanism in NSFilePresenter/NSFileCoordinator that will report any such changes to us? Detecting that a file has been modified or deleted is not difficult, but I don't think it's possible to detect that it has moved. Changes to directories are also difficult. Any advice? What does UIDocument do in this case?
Posted
by
Post not yet marked as solved
0 Replies
88 Views
Hello! I tried several times to restore an old version of a TextEdit file, but the "revert to" option doesn't work/keeps getting stuck on the loading phase and I have to force the app to quit. Everything is saved on my iCloud and I usually update the same files using to different computers (iMac and MacBook pro). Is there a solution or another way to recover the old version? My MacBook pro is currently update to Monterey 12.4 Thank you!
Posted
by
Post not yet marked as solved
6 Replies
254 Views
Hi. I want to make a planner app that has the date and location of the project. Only I have a problem. I used a "DatePicker" so that the date is counted. Only I do not know how to save and display the selected date. In general I have problems to save and reload the content of the variables and texfielders etc. I thought that these contents are automatically saved on the end device of the user. I have read that there are methods like "UserDefaults", "CoreData" or "AppStorage". Have been reading stuff about this forever. But I can't get this to work. I hope someone would like to donate their time to help. Greetings Janik
Posted
by
Post not yet marked as solved
1 Replies
114 Views
My app stores 3D models in the app's Documents folder. After the 15.5 update or one of the updates around then, the folder seems to only allow 34MB before refusing to let me write to the folder, regardless of how much memory is left on the phone. This has caused a critical problem, because the same file is being uploaded to my web service, due to the file not being over-written. Any idea what happened here?
Posted
by
Post not yet marked as solved
1 Replies
117 Views
I want to figure out whether a file (for which I have the absolute path) is a local file (on a disk device connected to my machine) or a remote file (connected over network). For the same what I have done is, I opened the file and then did a fstat on it (I know, I could have done without opening the file using stat, but that is okay). Now from fstat, I am looking at dev_t     st_dev;     /* ID of device containing file */   and figuring the major and minor version of the st_dev.   Now, what information which I have on Linux, about the different possible values of major version / minor version are present in devices.txt https://www.kernel.org/doc/Documentation/admin-guide/devices.txt   And the values match also (on Linux), for example for a local file (whether on hard disk/external hard disk or pen drive), I am getting major Version as 8.   What I want to know is, does Mac has similar devices.txt file? If yes, please provide the link/path.   If not, then what values can I assume right now, which will mean, file is remote?
Posted
by