How can I prevent two computers from opening the same file at the same time?

fryke

Moderator
Staff member
Mod
A customer was using Windows and we've switched them to Macs. All perfect. But! There seems to be no way of preventing two machines from accessing the same file at the same time. In Windows, Excel would say "this file is already opened on another machine" or something to that effect. The Macs simply open the file(s) and whoever saves last wins. This, of course, is a no-go.

How can I prevent a second Mac from opening a file that is already open on a first Mac? I'm stumped. I don't think the solution can be to tell them to call each other to ask whether a file is already opened somewhere...
 
There's this tip: Lock files and folders in Mac OS X, but this is a manual process - not an automatic one.

Locking a file is typically a request made of the OS by the program that opens the file. It's a problematic feature, because what happens if the program or computer crashes without un-locking the file ?!? In order for automatic locking of files to work, both the OS and the program requesting the file has to support the feature.

Additionally, there are two types of locks:
  • write only
  • both read and write
So, as far as I can see, Mac OS X supports locking files at the OS level. The problem is whether programs are requesting the feature.
 
Sadly, that's no solution for my problem, because while any of the users could lock the file, this would not stop them from having to talk to each other about _saving_ the file. (And if you lock the opening of the file, you yourself can't open it anymore.)
 
The way Excel does it is far from perfect (even on W). Is there a way to run a versioning system for your customer ?
 
No ideas there (Word FAQ, seriously?), though. ;) The Word FAQ sadly doesn't help (or my googling of the problem would've found it, anyway…). A versioning system… What are you thinking of exactly? Customer doesn't have a server yet, he's simply sharing one iMac's file system to the other Macs. (Basically, this _should_ be enough, we're only talking three computers in total and actually only three files that have to be accessed from the other two Macs.
 
Then versioning is not the right solution (I was thinking about the way we used to manage software and IC design documents, but this is server based, with a CVS or SVN server).

Microsoft is proposing to use SharePoint or SkyDrive, but again this is not what you are looking for.

Looks like a fundamental limitation.

Asking them to move the file when using it is probably too complex (have a "ready" and a "work-in-progress" directories - when someone wants to work on the file, he moves it from "Ready" to "work-in-progress", does the work, then moves it back. The file can always by read by all workers but the one who moves it to the "work-in-progress" get authorized to work on it, and he is responsible for moving it back when done).
 
I actually guess that's the way to go, though. They could add a short name of the user using it in front of the filename…

"filename" > rename to "fryke_filename" > edit > save > rename to "filename".

It would require quite some self-discipline, of course, but it would work, basically, if they adhere to a simple guideline. One could probably even write a script that renames and then opens the file if the file is there with its basic name, although the end-step would still have to be done (or another script started). I'll think about it.

What I don't like about the "solution": It's definitely *NOT* idiot-safe. ;)
 
Um Fryke, are these mac is a domain of some kind or are they just saving to shared NAS files?

1. If they are part of some kind of Domain then bookmark and troll the files at MacWindows.com. Pay close attention to the reader reports linked on the right side of the splash page, for a lot of reader reports and tips.

2. If the domain is using Server OS X then bookmark the site AFP548.com. They always seem to have some really good OS X server articles & tips.

3. If this just using a NAS and LAN sharing with Windows machines then getting rid of the dreaded .DS_Store files (here to remove them).

Now this is the first I have heard of the double opening of files and i see if on my NAS between my three Lion Macs opening the same file at the same time (just one user, me) using AFP sharing.

Does the same problem exists between different users on the same LAN? If it does I suggest on the NAS have separate folders, one folder for each user (created only by the user) and a general folder that all users can access. To me this would be a good work around.
 
I am not a fan of the name edition to access the file. It is good practice to identify backups but I am afraid it is too heavy for regular file usage.
 
Satcomer: Neither OS X Server or NAS, it's a rather simple setup…

They have two iMacs and a MacBook Air. The files are on one iMac (OS X Lion Client), shared via FileSharing. From the other iMac and the MacBook Air, users are logging in with the same user that is used on the first iMac.

We can't use separate files, because then we'd have, well, separate files. They all must use the same Excel file, so that there's always only one, accurate version. On Windows, this wasn't a problem, because if one user had the file open, another couldn't open it and had to wait, until the first user saved and closed the file. The Mac doesn't seem to know this kind of locking mechanism. (I think it's STANDARD behaviour in Windows!)

chevy: I agree, but I don't see a different solution as of now.
 
Satcomer: Neither OS X Server or NAS, it's a rather simple setup…

They have two iMacs and a MacBook Air. The files are on one iMac (OS X Lion Client), shared via FileSharing. From the other iMac and the MacBook Air, users are logging in with the same user that is used on the first iMac.

We can't use separate files, because then we'd have, well, separate files. They all must use the same Excel file, so that there's always only one, accurate version. On Windows, this wasn't a problem, because if one user had the file open, another couldn't open it and had to wait, until the first user saved and closed the file. The Mac doesn't seem to know this kind of locking mechanism. (I think it's STANDARD behaviour in Windows!)

chevy: I agree, but I don't see a different solution as of now.

Excel on Windows has several modes. If the file is in normal mode, as soon as one user opens it, is becomes read-only for other users (with the possibility to know when the first user updates the file). If the file is in shared mode, both users can edit it at the same time, the drawback being obviously that nobody knows if the content if completely up-to-date, another drawback of the share mode is that the file tends to become huge.
 
Did you try that (see image) ?
 

Attachments

  • Screen Shot 2012-03-02 at 11.31.29.png
    Screen Shot 2012-03-02 at 11.31.29.png
    62 KB · Views: 9
Just now I did. We didn't change anything, and the standard is, it seems, to _not_ let anyone else work on the file. I'm confused. Might even be a Lion-only problem… :/
 
Last edited:
Just now I did. We didn't change anything, and the standard is, it seems, to _not_ let anyone else work on the file. I'm confused. Might even be a Lion-only problem… :/

Submit a bug report and maybe apple will pay attention. Let me know if/what you report and I will back you up wityh my own report because in my testing the same thing happens on a NAS box between two different accounts (my Account and Test account).
 
I'll do that, but I'll have to test it with some of my own Macs using both 10.6 and 10.7. Do you use 10.7 exclusively on that NAS box with that problem?
 
Yep on the 10.7.x on all my Macs. Then NAS is my scratch drive connected to my Time Capsule.
 
Back
Top