On iOS, how can an app determine if a file is no longer being written to by another process? - iphone

My question is very similar to this one: What is the optimal way to monitor changes in a directory with a kqueue()? but I'm not satisfied with the answer there.
I have a kqueue setup to be notified when a file is copied to my app's Documents directory. Of course the notification fires as soon as the copying begins, but I want to know when it's completed. Surely there's a better way than polling modification times?

Do you initiate the copying and have control over the filenames ?
Then the easiest solution could be to just copy to a temp file and then after that rename it to it's final name.that way you would know: if this file is there-it ist no longer written to.

For now, the answer seems to be 'no', so I've resorted to polling the modification time of the file(s) in question.
If someone else is able to come up with a better answer, I'd be glad to hear it (and will un-accept this one).

Related

quick directory snapshot/hash

I'm looking for pointers to solutions for a problem that must have been solved multiple times (or pointers to the proper terms to search for):
How to get a reasonably quick/cheap directory snapshot/hash that can be used to determine whether something has changed compared to a previous state (which can be during a previous run of the code)?
Edit: I'm thinking here in the 1st place of added or deleted files/directories, but also of file changes that can be determined without reading the entire file.
Edit2: I'm looking for something cross-platform, and not a notification mechanism (sadly).
Thanks!

is watchman notifies for deleted files?

I tried to find in the documentation and I did not find indication.
I read the win32 watch code (because I am familiar with the API and it seems it does not).
Tracking for file deletion is extremely convoluted on windows, because the API provides the file names "randomly" mangled and if the file is not there anymore to resolve the real name "long path" it is hard to say what was the original.
I have implemented such thing for my previous company, with preserving the current state of files and reconciling the list of files for every directory that changes were happening inside. It worked well.
My question is: did I miss it and watchman notifies for deleted files? And if it does not - is there plans for these notifications to be added in the near future.
The short answer: yes.
The longer answer: the more convoluted portions are not entirely windows specific.
The bit that handles the mangled names can be found here:
https://github.com/facebook/watchman/blob/master/root.c#L748
The bit that handles deletes is in two parts; the first handles things when we're checking exactly the file that we were notified about:
https://github.com/facebook/watchman/blob/master/root.c#L853
The second is a kind of "garbage collection" approach where we're looking at the containing directory and discover that the file has gone away:
https://github.com/facebook/watchman/blob/master/root.c#L1353

Back and Rollback Script for a File Transfer

I looking for a good solution to backup and rollback a folder using the Windows(XP/Vista/7) OS.
As an example, say, I have a folder, called "\SOMEOTHERPC\Destination" (that contains files and subfolders). I wish to take a back up of this folder to my local disk. Then, say I was to edit or delete some of the content of this "\SOMEOTHERPC\Destination" folder and the afterwards rollback the folder to its previous state.
What's the best way to go about this. I am thinking of writing a PowerShell script? Perhaps there is a better way. Any suggestions appreciated?
Thanks.
RoboCopy seems to do the trick requiring just a couple of lines of script.

Automated versioning of files in file share?

We have a file share on a debian server which people will be putting mostly small plain text, word, excel, pdf, misc, files into. We want to keep file level versioning of everything placed in that file share. We'd like all of the versioning to happen automatically in the background every time a change is made to a file.
What's the easiest open source way to do this? What's the best versioning system to do this with? Is there an automated versioning system like this out there somewhere?
I'm not asking for complete instructions. I'm just looking for recommendations or keywords to search with (other than "automatic versioning files" which didn't find me much).
We're already backing up the volume many times a day. We don't want to do volume snapshots etc. We're looking for some kind of automated file level versioning.
Update:
Using incron to autocommit changes in a folder:
http://andrew.mcmillan.net.nz/blog/using_incron_to_autoversion_a_directory
Thanks to using the new keyword "autoversioning" I found the above which I'm interested in. It's a script which is triggered from incron every time a file changes. One problem is incron isn't recursive.
I would try a versioned filesystem, such as ext3cow or nilfs.
I have no experience with them, but they have always looked like a very interesting idea to me.
The SVNAutoVersioning directive to mod_dav_svn is one solution.

emacs local version control

I am wondering if there is local version control/snapshots for emacs independent of VC?
let me clarify:
every time I save buffer, I would like to be able to keep track of changes of each save in session. I know I can do something similar with backup files, but they are not automated like VC and a somewhat cumbersome.
I have searched Google, but did not find the solution.
Perhaps my query string was not good.
I found this for eclipse, am looking for emacs equivalent:
http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.platform.doc.user/gettingStarted/qs-55.htm
Thanks
AFAIK there is no such solution, but you can make some ad hoc one - like creating a local VCS repository and advice the save-buffer command to commit the changes in the repository.
I also came across a section of the manual that might be of interest to you.
I don't know of a way to get Emacs to save buffer snapshots, but keep in mind that it has an infinite undo facility. If you just want a way to get back to earlier versions, that might help you. If you want real version control, then I'd go with Bozhidar Batsov's solution and advice the save-buffer command.
http://www.emacswiki.org/emacs/BackupEachSave