Is it good way to use /tmp in application for storing temporary files? - tmp

In my application, we store temporary images generated from PDF in /tmp/pdf_images folder. Is it a standard practice? Or It's not recommended to use of /tmp from application code?

Assuming you're on linux or MacOS, this directory is just there for this.
Be sure to have them automatically deleted at closing of your application.
And note that they may be purged by the OS or the user (directly or not) at any moment when your application isn't running. And generally, it's totally cleaned at reboot (and every 3 days on MacOS).

Related

We are using ResilioSync on QNAP NAS and one of our NAS got hit by QLocker ransomware, what can we do?

We got hit by the QNAP QLocker ransom ware on our NAS and it encrypted a lot of files (datasets) that we are sharing by ReslioSync.
Is there some way to restore the files?
Yes if you are quick enough to deal with it before the default ResilioSync archiving time of 30 days.
Any other sync that shares the same file will have the unencrypted file in its Resilio .sync/Archive folder. You can simply copy the contents of Archive back to the top level, as long as you are OK with overwriting any file that may have been modified and stored in the archive as well.
If you want to get fancier, you can check the dates and you will see that QLocker encrypted most files within a short period.

having external files in an electron application

I have an electron app, and when I make it, it packages and compiles everything.
Sounds like it works perfectly right?
Well, problem is I want one of the folders to not be compiled, but still be accessible by my static files, so the users can add or remove content from the folders.
I've tried making it in a seperate folder, but then it can't find the files even when it's placed in the correct relative path.
Overall, I want my app to exist next to a folder and my <script src="./folder/script.js"></script> to actually be able to access it.
I'm new to basically anything node or electron so i'm probably making some dumb mistake.
Thanks in advance.
Having your user touching files close to your Electron application may be fraught with danger. If they accidently overwrite an important file or accidently delete an important file then your application may stop working and require the user to perform a re-install.
Instead, have any default files the user may need to "touch" packaged up with your application and then upon your applications first run, copy these files (and any necessary folder structure) over to the users home, desktop, documents, downloads or even userData directory.
That way, your application will always know where to find them and the directory is a directory your user will already be comfortable adding files to and removing files from.
You can always let the use choose where these files are stored as a settings option which persists in an application setting file, using something similar to path.join(app.getPath('userData'), 'settings.json');
See Electron's app.getPath(name) for more information.

How to move Active Storage data from one machine to another

Because reasons we are trying to move a system from one machine to another one. It has several files in the storage directory. I rsynced it (using -a) to a local environment to see if everything works, but turns out not all the files are available, some of them raise an exception:
Errno::ENOENT (No such file or directory # rb_file_s_mtime - /path/to/project/storage/as/df/asdfasdfasdfasdfasdf):
Of course I checked the routes and they exists. I've been reading a bit about how Active Storage works and I maybe the URLs are getting invalidated for some reason, but why some files work? 🧐 Why the exception mentions mtime? And more importantly, how can I do the migration smoothly?
Thanks in advance
So the problem is actually the filesystems + Active Record names 😰 You can consider this a corner case: My local machine runs macOS, while the server runs Linux, so if I had folders Vf and VF on Linux, on macOS they become one (whichever is downloaded firs). Active Storage relies on case-sensitive filenames, and that's why some of the files work fine, but others are not found

Saving file to tmp directory when iphone/ipad storage is full

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).

Keeping temporary files after quiting WinSCP

I set the WinSCP temporary directory on my hard-drive, but after quitting WinSCP the files stored there get deleted.
Is it possible to prevent them from being deleted? So I can edit them or copy them later.
And if its possible, can WinSCP automatically load those files, if they are newer than the ones on the server? This is optional, but it would be good.
Is it possible to prevent them from being deleted?
Yes, the option is named Keep temporary copies of remote files in deterministic paths.
Can WinSCP automatically load those files, if they are newer than the ones on the server?
WinSCP has function Keep remote directory up to date that monitors local folder and automatically uploads any changes to the server.
If you run two instances of WinSCP, you can combine these two features, but it's quite strange setup.

Resources