Update of /cvsroot/mahogany/M/include
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv24751/include

Modified Files:
        sysutil.h 
Log Message:
allow passing a wxFile to open on the generated temp file name to MTempFile 
ctor to avoid race conditions

Index: sysutil.h
===================================================================
RCS file: /cvsroot/mahogany/M/include/sysutil.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -b -u -2 -r1.10 -r1.11
--- sysutil.h   18 Sep 2003 16:30:43 -0000      1.10
+++ sysutil.h   31 Aug 2006 23:45:05 -0000      1.11
@@ -1,17 +1,16 @@
-/*-*- c++ -*-********************************************************
- * sysutil.h : utility functions for various OS functionality       *
- *                                                                  *
- * (C) 1999 by Karsten Ballüder ([EMAIL PROTECTED])                 *
- *                                                                  *
- * $Id$
- *
- *******************************************************************/
+///////////////////////////////////////////////////////////////////////////////
+// Project:     M - cross platform e-mail GUI client
+// File name:   include/sysutil.h
+// Purpose:     utility functions for various OS-level functionality
+// Author:      Karsten Ballüder, Vadim Zeitlin
+// Created:     1999
+// CVS-ID:      $Id$
+// Copyright:   (c) 1999 Karsten Ballüder
+//              (c) 2000-2006 Vadim Zeitlin <[EMAIL PROTECTED]>
+// Licence:     M license
+///////////////////////////////////////////////////////////////////////////////
 
-
-#ifndef SYSUTIL_H
-#define SYSUTIL_H
-
-#ifndef  USE_PCH
-#endif // USE_PCH
+#ifndef M_SYSUTIL_H
+#define M_SYSUTIL_H
 
 #include <wx/filename.h>
@@ -39,25 +38,48 @@
 {
 public:
-   // def ctor: creates the temp file and doesn't delete it unless told to do
-   // so (i.e. Ok() is called)
-   MTempFileName() : m_name (wxFileName::CreateTempFileName(_T("Mahogany")))
-      { m_ok = false; }
-
-   // ctor which takes a temp file name: still won't be deleted unless Ok() is
-   // called
-   MTempFileName(const String& name) : m_name(name) { m_ok = false; }
+   /**
+      Ctor creates a temporary file name and possibly associates it with the
+      specified file.
+
+      If the temp file name is used for writing some data to it, the file
+      parameter must be specified as otherwise the operation wouldn't be atomic
+      and race conditions could occur. Do close the file before this object
+      goes out of scope in this case though as otherwise we could fail to
+      delete the temp file under Windows.
+
+      @param file if non-NULL, the file to open (for writing) with the
+                  temporary file name
+    */
+   MTempFileName(wxFile *file = NULL)
+      : m_name(wxFileName::CreateTempFileName(_T("Mahogany"), file))
+   {
+      m_keepFile = false;
+   }
+
+   /**
+      Ctor from an existing temporary file name.
 
-   /// returns FALSE if temp file name couldn't be generated
-   bool IsOk() const { return !!m_name; }
+      The specified file will be deleted when this object is destroyed unless
+      Ok() is called.
 
-   /// get the name of the temp file
+      @param name of the existing temporary file
+    */
+   MTempFileName(const String& name) : m_name(name)
+   {
+      m_keepFile = false;
+   }
+
+   /// Returns false if temp file name couldn't be generated
+   bool IsOk() const { return !m_name.empty(); }
+
+   /// Get the name of the temp file
    const String& GetName() const { return m_name; }
 
-   /// tells us not to delete the temp file
-   void Ok() { m_ok = true; }
+   /// Tells us not to delete the temp file
+   void Ok() { m_keepFile = true; }
 
    ~MTempFileName()
    {
-      if ( !m_ok && !m_name.empty() )
+      if ( !m_keepFile && !m_name.empty() )
       {
          if ( wxRemove(m_name) != 0 )
@@ -70,8 +92,9 @@
 private:
    String m_name;
-   bool   m_ok;
+   bool   m_keepFile;
 };
 
 //@}
-#endif
+
+#endif // M_SYSUTIL_H
 


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Mahogany-cvsupdates mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to