Re: Gnumeric file-locking in 0.70, includes diff -cr



On Tue, Sep 25, 2001 at 09:57:48PM +0200, Joost Helberg wrote:
simple: exlusive. The far more fancier solution GNU Emacs implements
is beyond me for now.
ok.
 
My fix (included below) works OK for me now. I'm willing to go the
full way by adding flock-checking to configure and adding
dialogue-invocation in case a users tries to open a locked file. The
dialogue now is perror, nothing more, nothing less. Although gnumeric
handles this higher up by alerting: `cannot open workbook'.
That should be fixable.

But first I'd like to know whether you are willing to accept
file-locking as a feature and whether you think I did a good job in
adding *close* to the various API's within gnumeric before
implementing it in file.c.
This fits into our rather messy api nicely.

PPS: another feature I'll implement is the creation of backup-files ?
la GNU Emacs.
That would also be nice.
 
  gnum_file_opener_open (GnumFileOpener const *fo, IOContext *io_context,
                         WorkbookView *wbv, const gchar *file_name)
  {
+         int fd;
      g_return_if_fail (IS_GNUM_FILE_OPENER (fo));
      g_return_if_fail (file_name != NULL);
  
+         fd = open( file_name, 0 );
this appears to leak afile descriptor.

+            if( flock( fd, LOCK_EX | LOCK_NB ) != 0 )
hmm, flock has limitations that make it less than useful.
According to the glibc man page it does not work over nfs,
and they advocate fcntl instead.  However, even that seems to have
version issues.  We may want to adopt a simpler akin to what vim
uses.  It create a .file.swp file whenever it is editng a file.
The swp file includes info such as machine name, pid, and user.
That way when another process attempts to open the file it has
enough info to explain why it can't.  Very low tech, but probably
more effective and portable.  It would require work in a different
location, but should be feasible.

+         else
+         {
+            perror( "Open for locking failed" );
You could have reported the details via the io_context.

  
+ void gnum_file_opener_close( const gchar *file_name )
+ {
+    int fd;
+    fd = open( file_name, 0 );
also leaks a descriptor.

--- gnumeric-0.70/src/workbook-control-gui.c  Tue Sep 25 21:46:58 2001
***************
*** 1206,1211 ****
--- 1206,1212 ----
      in_can_close = FALSE;
  
      if (can_close) {
+             gui_file_close(wbcg, wb->filename );
              workbook_unref (wb);
              return FALSE;
      } else
I'd rather do this as part of workbook_destroy given that we can't
really have an error at this point.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]