If you create, save and run a Python IDLE file, is the file saved forever?
You cannot run it unless you save it. (By clicking Save As) So yes, the file will be saved forever, until you delete it.
Related
When I save (either create or update) a small file in the iCloud container of my iOS app, the iCloud daemon first uploads the file to iCloud and then evicts it when the upload is done. If I monitor the file's state using a NSMetadataQuery I can see that after the save, the file's downloading status changes fromNSMetadataUbiquitousItemDownloadingStatusCurrent to NSMetadataUbiquitousItemDownloadingStatusNotDownloaded, and instead of my little test file named test I only see the file .test.icloud instead.
This is bad because if the user goes offline after the file creation, the file cannot be read again. The file should always be available locally after the creation (an outdated file is better than no file).
I know that I can immediately re-download the file using FileManager's method startDownloadingUbiquitousItem after iCloud removes it, but this feels like a silly hack. Is there a way to simply prevent iCloud from evicting the file in the first place?
I have a rails app where the user can upload files. The files get uploaded to an external cloud service by a backgroud jobs. It's vital for my app that the files won't get stored in the file system after they've been uploaded. Not right away, in general -- they must not remain in the file system.
Should I delete them on my own? Or will get deleted automatically?
Also, debugging my app, I noticied this for an attachment params:
[2] pry(#<MyController>)> my_params.tempfile.path
"/var/folders/qr/0v5z71xn7x503ykyv1j6lkp00000gn/T/RackMultipart20181007-10937-3ntmgg.png"
That file gets stored not in "/tmp" but in "/var" and that means that it won't get deleted automatically, right?
Note that I'm not using paperclip for this task.
You are right the files won't get deleted automatically.
You have to delete the file explicitly at some point in time.
It depends how you set it up. If you used Tempfile to save it then yes the files will be deleted when the object is garbage collected. If not then it probably won't be deleted.
If the files get stored on an external service it might be worth setting up ActiveStorage which allows you to directly upload to external storage providers without the file ever touching your server.
Let's say an app downloads images from web while the user is browsing the app. Let's assume there are virtually unlimited images and a new image is downloaded whenever the user demands one. These images are saved to tmp directory for caching purpose. Once the user closes the app, all the images downloaded are deleted by the app.
Now, as there are unlimited images, what will happen if the user requests next image, the storage is full and the app attempts to save the image to the tmp directory?
Will the previous images be deleted by the iOS automatically to provide the space required for the new images?
OR
Will the iOS start cleaning tmp directory associated with other apps?(If yes, what happens when the storage is full again and such cleaning has already taken place for all the other apps?)
OR
Will the app crash?
If you try and save a image to disk and the disk is full then NSData's
- (BOOL)writeToURL:(NSURL *)aURL
options:(NSDataWritingOptions)mask
error:(NSError **)errorPtr
Will return NO and an error object will be assigned to the errorPtr passed into the method. This error will have a NSFileWriteOutOfSpaceError. This error is very exceptional, and by the time you get it it's safe to say the system will have already notified the user that he is running out of disk space.
Having said that, a lot can be said about cleaning after yourself. If you're not going to use a saved image resource anymore then delete it from the file-system.
Cheers!
tmp/
Use this directory to write temporary files that do not need to persist between launches of your app. Your app should remove files from this directory when they are no longer needed; however, the system may purge this directory when your app is not running.
The contents of this directory are not backed up by iTunes.
That's the only thing documented. From this I can infer that it won't purge you tmp if your app is running,but it can purge the tmp of other apps which are not running
As #InderKumarRathore says, the docs imply that the system will not delete files from your temp directory when your app is running. The docs also don't promise that the system will delete contents from other apps' temp directories to make space for you.
I would suggest coding defensively: Keep track of the oldest/least recently used files in your temp directory and delete them yourself. Preflight file saves to make sure there is enough space, and display a message to the user if there isn't enough space to save the file(s).
I have an app that creates a backup of my Core Data store and stores it in the NSDocuments directory. When I try to restore from that directory (without restarting the app), everything is restored correctly. However, if I stop the app, restart it and try to do a restore, the directory is different and the restore uses an old version of the backup file (haven't a clue where it came from).
My question is: because I need to persist the latest backup file, where can I save it so it will be there when I need it? (possibly after many distinct executions of my app). I don't want to use iTunes, so I was thinking of possibly iCloud; I need something that is not accessable to the user so he/she can't accidently delete the backup file.
Library/ApplicationSupport will do what I need... (just in case someone else needs the same info). SD
In my iPhone app, I am downloading files from server and storing them locally (user's document directory). The path of each file downloaded is subsequently updated in database.
If user tries to delete a file, first the file is deleted from local path using removeItemAtPath: (NSFileManager), then corresponding record is deleted from database.
Now I have one of the requirements according to which user can turn on a UISwitch to delete all data on app exit.
Now my question is -
suppose user downloaded 20000 files, say small images, and user turned
on the switch to delete all data on app exit. Is it good to handle
this task in applicationWillTerminate? What is the best way to
accomplish this scenario?
Please suggest.
Don't delete the files individually, delete and recreate the folder.
Your database could be handled differently by version tagging so that you can batch delete the items on the next run.
applicationWillTerminate will only be called if your app goes background (the only option by pressing Home button of the device) and "Application does not run in background" key is set in your app's info.plist file to "YES". Otherwise it won't ever be called.
If you are planning deploy app with similar functionality, you can use applicationWillTerminate for removing so many files. However, I would never recommend you that. Instead, my recommendation is to remove the files as soon as they are processed, if possible at all.
Another thing you must consider is not to save so many files in Document directory, however small those are. Document directory is backed up by iTunes and iCloud and if you store so many files there, you are gonna possibly violate Apple's Data Storage Guideline that would reject your app from App Store. It is always a good idea to store transient files in application's "tmp" directory and delete them when not required anymore.