Update of /cvsroot/mahogany/M/src/mail
In directory usw-pr-cvs1:/tmp/cvs-serv31885/src/mail

Modified Files:
        MailFolderCC.cpp 
Log Message:
ask for confirmation before deleting a non empty lock file

Index: MailFolderCC.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/mail/MailFolderCC.cpp,v
retrieving revision 1.616
retrieving revision 1.617
diff -b -u -2 -r1.616 -r1.617
--- MailFolderCC.cpp    10 May 2002 14:10:01 -0000      1.616
+++ MailFolderCC.cpp    14 May 2002 00:07:49 -0000      1.617
@@ -62,4 +62,5 @@
 
 #include <ctype.h>   // isspace()
+#include <sys/stat.h>   // struct stat
 
 #ifdef OS_UNIX
@@ -2344,9 +2345,12 @@
 MailFolderCC::CheckForFileLock()
 {
-   String lockfile;
+   // this code doesn't work under Windows anyhow because lockname() doesn't
+   // use ".lock" suffix there
+#ifdef OS_UNIX
+   String file;
 
    MFolderType folderType = GetType();
    if( folderType == MF_FILE )
-      lockfile = m_ImapSpec;
+      file = m_ImapSpec;
 #ifdef OS_UNIX
    else if ( folderType == MF_INBOX )
@@ -2354,7 +2358,7 @@
       // get INBOX path name
       MCclientLocker lock;
-      lockfile = (char *) mail_parameters (NIL,GET_SYSINBOX,NULL);
-      if(lockfile.empty()) // another c-client stupidity
-         lockfile = (char *) sysinbox();
+      file = (char *) mail_parameters (NIL,GET_SYSINBOX,NULL);
+      if(file.empty()) // another c-client stupidity
+         file = (char *) sysinbox();
    }
 #endif // OS_UNIX
@@ -2365,37 +2369,62 @@
    }
 
-   lockfile << ".lock*"; //FIXME: is this fine for MS-Win? (NO!)
-   lockfile = wxFindFirstFile(lockfile, wxFILE);
+   // TODO: we should be using c-client's lockname() here
+   String lockfile = wxFindFirstFile(file + ".lock*", wxFILE);
    while ( !lockfile.empty() )
    {
-      FILE *fp = fopen(lockfile,"r");
-      if(fp) // outch, someone has a lock
-      {
-         fclose(fp);
-         String msg;
-         msg.Printf(_("Found lock-file:\n"
-                    "'%s'\n"
+      // outch, someone has a lock, opening the mailbox will fail as c-client
+      // checks for it -- propose to the user to remove the lock first
+      bool shouldRemove = MDialog_YesNoDialog
+                          (
+                           String::Format(
+                              _("Found lock-file '%s' for the mailbox '%s'.\n"
+                                "\n"
                     "Some other process may be using the folder.\n"
                     "Shall I forcefully override the lock?"),
-                    lockfile.c_str());
-         if(MDialog_YesNoDialog(msg, NULL,
-                                MDIALOG_YESNOTITLE, M_DLG_YES_DEFAULT))
-         {
-            int success = remove(lockfile);
-            if(success != 0) // error!
-               wxLogWarning(_("Could not remove lock-file.\n"
-                              "Other process may have terminated.\n"
-                              "Will try to continue as normal."));
+                              lockfile.c_str(), file.c_str()
+                           ),
+                           NULL,
+                           MDIALOG_YESNOTITLE,
+                           M_DLG_YES_DEFAULT
+                          );
+
+      if ( shouldRemove )
+      {
+         // ask extra confirmation if the file is not empty to avoid deleting
+         // the important files erroneously
+         wxStructStat stBuf;
+         if ( wxStat(lockfile, &stBuf) != 0 || stBuf.st_size != 0 )
+         {
+            shouldRemove = MDialog_YesNoDialog
+                           (
+                              String::Format(
+                                 _("The file '%s' is not empty, still remove it?"),
+                                 lockfile.c_str()),
+                              NULL,
+                              MDIALOG_YESNOTITLE,
+                              M_DLG_NO_DEFAULT
+                             );
          }
-         else
+      }
+
+      if ( shouldRemove )
          {
-            wxLogError(_("Cannot open the folder while lock-file exists."));
-            wxLogError(_("Could not open mailbox %s."), GetName().c_str());
+         // remove the file but be prepared to the fact that it could have
+         // already disappeared by itself
+         if ( remove(lockfile) != 0 && wxFile::Exists(lockfile) )
+         {
+            wxLogSysError(_("Failed to remove the lock file"));
 
             return false;
          }
       }
+      else if ( wxFile::Exists(lockfile) )
+      {
+         wxLogWarning(_("Lock file is present, opening the folder might fail."));
+      }
+
       lockfile = wxFindNextFile();
    }
+#endif // OS_UNIX
 
    return true;


_______________________________________________________________

Have big pipes? SourceForge.net is looking for download mirrors. We supply
the hardware. You get the recognition. Email Us: [EMAIL PROTECTED]
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to