View Full Version : Linux: Delete file problem if one happens to be in use. any DeleteLater function?

24th January 2013, 23:31
Hey all, i have an application suite where it needs to manage a queue of files between two applications. The player is playing all the files in a directory, while the updater may add or remove files to it based on a CRON Schedule...

the problem becomes when coincidentally, i need to delete a file while the player is using it. Of course i need to wait till the player is done, but there is no DeleteLater... One thought was to just add the file names that fail to remove to another Queue, to go back and try them again, but before i go though all that i wanted to see if there was another reason.

Here is the simple function i am using... Pseudo-code.

if (dir.exists(mediafile)) {

// TODO: How to handle if the file is in use.

// "file removed";

} else {

// "unable to remove the file";

} else {

// "In path:" << dir.path();
// "unable to find the mediafile: " << mediafile;


25th January 2013, 14:53
No, there is no "DeleteLater" functionality. File handling is very dependent on the underlying filesystem. It could be that some filesystems contain ioctl() calls that provide services similar to what you seek but there is no general solution to the problem.

27th January 2013, 14:14
You can delete a file that is currently being used by another process without any problem. The entry in the directory is being removed but all handles to the file stay valid.

So basically Linux (and most other Unix-like systems) already implement a "delete later" behavior by default.