The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Simple document locking over the network

In the last week I have had a couple of customers asking about simultaneous access to PerfectTablePlan plan files on a shared drive across a Windows network. PerfectTablePlan is a desktop app, not client-server - the plan files are just XML/text. Is there some simple way that they can ensure they aren't overwiting each other's changes? And I mean simple - I am not moving to client-server and these people won't be installing subversion any time soon. Is there any way to detect if someone has opened a file from another client? or is there a simple third party solution I can advise them to install.

If it works on Mac as well, that would be even better!
Andy Brice Send private email
Monday, February 06, 2006
 
 
Andy, why not just lock the file when you open it and keep it locked for the duration or am I missing something here?

Following a JoS recommendation last week I listened to some PodCasts from SavSoloCast over the w/e. You should listen to http://savvysolocast.com/2005/11/25/savvysolocast-25-conversation-with-a-marketing-headhunter/ where harry talks about brides to be. Good stuff.
Neville Franks Send private email
Monday, February 06, 2006
 
 
I've just tried it with Excel and it realises that a spreadsheet has already been opened in a remote machine. Is it using a Win32 API call to work this out? If so, what it the magic function? Or is it using some sort of custom semaphore?
Andy Brice Send private email
Monday, February 06, 2006
 
 
>Andy, why not just lock the file when you open it and keep it locked for the duration or am I missing something here?

<slaps forehead>Is it really that simple? Is that all that Excel does?

Currently I only keep the file open for the duration of a read or write and then close it again. That works fine for single user, but its no good for multi-user.

I never really envisaged the software being used in a multi-user environment. I guess its a victim of its own success.
Andy Brice Send private email
Monday, February 06, 2006
 
 
There are several Windows API's for monitoring and detecting file and folder changes, but I don't think you need to head down this track.

When you open the file specify the deny read-write options and keep the file open until the app closes. When it starts check the error that open returns and if its a sharing violation tell the user the file can't be opened because it is in use.

You may be able to get smarter and open the file for read-deny write access. Then let other instances have read-only access.
Neville Franks Send private email
Monday, February 06, 2006
 
 
Depending the API you are using to open the file, you can set the file access attribute to exclusive_write or exclusive_read.
If the document is to be accessed by multiple user, you need to implmeent locking on record level, which is a complicated topic.
Burnder
Monday, February 06, 2006
 
 
But you want to write changes to the file frequently, in case the system goes down in the middle of an editing session.  You can keep the original file open, then save a temporary file copy on the local machine, then when the user exits save the temp to the original and delete the temp.

Not exactly what you were asking about today, but something to consider.
Karl Perry Send private email
Monday, February 06, 2006
 
 
An extremely primitive solution - add an XML flag that indicates the file is in use.

When you first open the file, modify the flag and immediately save it.

When you close the application, un-modify the flag and save - this can be part of your "do you want to save your work before exiting" dialog box.

There will be cases you'll abnormally exit the application - but since this is an XML file, you can provide an "override" mechanism, or a help file that describes how to change the flag in Notepad (or the Mac equivalent which I think is TextEdit).
TheDavid
Monday, February 06, 2006
 
 
>There will be cases you'll abnormally exit the application - but since this is an XML file, you can provide an "override" mechanism, or a help file that describes how to change the flag in Notepad (or the Mac equivalent which I think is TextEdit).

I think that would quadruple my support load overnight.
Andy Brice Send private email
Monday, February 06, 2006
 
 
Check out how it's handled here:

http://www.codeproject.com/tools/todolist2.asp

It's a good application, and the source code is available too!

(When using the app, try Tools->Preferences->Multiple Users)
Warren Stevens Send private email
Monday, February 06, 2006
 
 
The override would be a better solution then.  :)

If you can capture the user name and put that in the XML file, then you basically get a dialog box that says "TheDavid is currently using this program. Do you want to kick him off? [Yes] [No]."

I would think most users at this point would just call me and ask me if I was done.
TheDavid
Monday, February 06, 2006
 
 
Thanks for the suggestions. File level locking is fine for my needs.

My software is written on top of the Qt framework and it turns out that some kind person at Trolltech has written a portable file locking class to sit on top of Qt:

http://www.trolltech.com/products/solutions/catalog/3/Utilities/qtlockedfile/

So I shouldn't even have to grub around in the MacOSX/Win32 APIs. Hurrah!
Andy Brice Send private email
Monday, February 06, 2006
 
 
You can also use memcached type systems for network locks.
son of parnas
Monday, February 06, 2006
 
 
> When you first open the file, modify the flag and immediately save it.

That doesn't work, when two users 'simultaneously' open the file and 'simultaneously' modify the flag.

O/S-level locking works (because the O/S on the remote machine serializes lock requests and grants only the first one).
Christopher Wells Send private email
Tuesday, February 14, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz