myserver-commit
[Top][All Lists]
Advanced

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

[myserver-commit] [SCM] GNU MyServer branch, master, updated. v0.9.2-240


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. v0.9.2-240-gd6791be
Date: Sun, 16 May 2010 11:26:20 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU MyServer".

The branch, master has been updated
       via  d6791bead4a08d3aedfc6961ab2f111f291f06fd (commit)
       via  96182a5d07f6e341f332403303bd229d76a33d1a (commit)
       via  7c07c7987f544d60a9b29ed45be2a661f03582bc (commit)
      from  acffb7a7648a70a05a12649b173bc738cf0500e6 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------


commit d6791bead4a08d3aedfc6961ab2f111f291f06fd
Author: Giuseppe Scrivano <address@hidden>
Date:   Sun May 16 13:22:24 2010 +0200

    Add a new argument mask to `File::openFile'.

diff --git a/myserver/include/base/file/file.h 
b/myserver/include/base/file/file.h
index efcdd96..fe38dfd 100644
--- a/myserver/include/base/file/file.h
+++ b/myserver/include/base/file/file.h
@@ -55,9 +55,9 @@ public:
   virtual int writeToFile (const char *, u_long , u_long *);
   virtual int createTemporaryFile (const char *, bool unlink = true);
 
-  virtual int openFile (const char *, u_long);
-  virtual int openFile (string const &file, u_long opt)
-  {return openFile (file.c_str (), opt);}
+  virtual int openFile (const char *, u_long, mode_t mask = 00700);
+  virtual int openFile (string const &file, u_long opt, mode_t mask = 00700)
+  {return openFile (file.c_str (), opt, mask);}
 
   virtual u_long getFileSize ();
   virtual int seek (u_long);
diff --git a/myserver/src/base/file/file.cpp b/myserver/src/base/file/file.cpp
index 53b8ae4..8b2ba64 100644
--- a/myserver/src/base/file/file.cpp
+++ b/myserver/src/base/file/file.cpp
@@ -127,13 +127,14 @@ void File::fstat (struct stat *fstat)
 }
 
 /*!
- *Open (or create if not exists) a file, but must explicitly use read and/or
- *write flags and open flag.
- *\param nfilename Filename to open.
- *\param opt Specify how open the file.
- *openFile returns 0 if the call was successful, any other value on errors.
+  Open (or create if not exists) a file, but must explicitly use read and/or
+  write flags and open flag.
+  \param nfilename Filename to open.
+  \param opt Specify how open the file.
+  \param mask Creation mode when a new file is created.
+  openFile returns 0 if the call was successful, any other value on errors.
  */
-int File::openFile (const char* nfilename, u_long opt)
+int File::openFile (const char* nfilename, u_long opt, mode_t mask)
 {
   int flags;
 



commit 96182a5d07f6e341f332403303bd229d76a33d1a
Author: Giuseppe Scrivano <address@hidden>
Date:   Sun May 16 11:18:00 2010 +0200

    Save a `stat' when a file is opened.
    
    Remove FILE_CREATE_ALWAYS from the open flags.  It can be considered a
    duplicate for FILE_OPEN_ALWAYS.

diff --git a/myserver/include/base/file/file.h 
b/myserver/include/base/file/file.h
index a267e4b..efcdd96 100644
--- a/myserver/include/base/file/file.h
+++ b/myserver/include/base/file/file.h
@@ -42,9 +42,8 @@ public:
       FILE_OPEN_ALWAYS = (1 << 5),
       OPEN_IF_EXISTS = (1 << 6),
       APPEND = (1 << 7),
-      FILE_CREATE_ALWAYS = (1 << 8),
-      NO_INHERIT = (1 << 9),
-      NO_FOLLOW_SYMLINK = (1 << 10)
+      NO_INHERIT = (1 << 8),
+      NO_FOLLOW_SYMLINK = (1 << 9)
     };
 
   File ();
diff --git a/myserver/src/base/file/file.cpp b/myserver/src/base/file/file.cpp
index 530632b..53b8ae4 100644
--- a/myserver/src/base/file/file.cpp
+++ b/myserver/src/base/file/file.cpp
@@ -135,7 +135,6 @@ void File::fstat (struct stat *fstat)
  */
 int File::openFile (const char* nfilename, u_long opt)
 {
-  struct stat fStats;
   int flags;
 
   filename.assign (nfilename);
@@ -150,44 +149,22 @@ int File::openFile (const char* nfilename, u_long opt)
   if (opt & File::NO_FOLLOW_SYMLINK)
     flags = O_NOFOLLOW;
 
-  /* FIXME: how avoid a stat?  */
-  bool exists = stat (filename.c_str (), &fStats) == 0;
-  if (opt & File::OPEN_IF_EXISTS && !exists)
-    return 1;
-
-  if (exists && (opt & File::APPEND))
+  if (opt & File::APPEND)
     flags |= O_APPEND;
 
-  if (exists)
-    handle = checked::open (filename.c_str (), O_APPEND | flags);
-  else
-    handle = checked::open (filename.c_str (), O_CREAT | flags,
-                            S_IRUSR | S_IWUSR);
-
-  try
+  handle = gnulib::open (filename.c_str (), flags);
+  if (handle < 0)
     {
-      if (opt & File::FILE_CREATE_ALWAYS)
-        if (truncate ())
-          {
-            close ();
-            return -1;
-          }
- 
-      if (opt & File::TEMPORARY)
-        if (checked::unlink (filename.c_str ()))
-          {
-            close ();
-            return -1;
-          }
-    }
-  catch (exception &e)
-    {
-      /* Ensure the file is closed if something went wrong and don't leave
-         open descriptors around.  */
-      close ();
-      throw;
+      if (! ((errno == ENOENT) && (opt & File::FILE_OPEN_ALWAYS)))
+        checked::raiseException ();
+
+      flags |= O_CREAT;
+      handle = checked::open (filename.c_str (), flags, S_IRUSR | S_IWUSR);
     }
 
+  if (opt & File::TEMPORARY)
+    checked::unlink (filename.c_str ());
+
   this->opt = opt;
   return handle < 0;
 }
@@ -254,7 +231,7 @@ int File::createTemporaryFile (const char* filename, bool 
unlink)
   u_long temporaryOpt = unlink ? File::TEMPORARY : File::TEMPORARY_DELAYED;
 
   return openFile (filename, File::READ | File::WRITE | File::NO_INHERIT
-                   | File::FILE_CREATE_ALWAYS | temporaryOpt);
+                   | File::FILE_OPEN_ALWAYS | temporaryOpt);
 }
 
 /*!
diff --git a/myserver/src/base/file/files_utility.cpp 
b/myserver/src/base/file/files_utility.cpp
index 1151a35..09ede45 100644
--- a/myserver/src/base/file/files_utility.cpp
+++ b/myserver/src/base/file/files_utility.cpp
@@ -158,7 +158,7 @@ int FilesUtility::copyFile (const char* src, const char* 
dest, int overwrite)
     return -1;
 
   if (destFile.openFile (dest, File::WRITE
-                         | (overwrite ? File::FILE_CREATE_ALWAYS : 0)))
+                         | (overwrite ? File::FILE_OPEN_ALWAYS : 0)))
     {
       srcFile.close ();
       return -1;
diff --git a/myserver/src/http_handler/http_file/http_file.cpp 
b/myserver/src/http_handler/http_file/http_file.cpp
index 910827c..381e67f 100644
--- a/myserver/src/http_handler/http_file/http_file.cpp
+++ b/myserver/src/http_handler/http_file/http_file.cpp
@@ -77,7 +77,7 @@ int HttpFile::putFile (HttpThreadContext* td, string& 
filename)
         /* The file doesn't exist.  */
         try
           {
-            file.openFile (td->filenamePath.c_str (), File::FILE_CREATE_ALWAYS
+            file.openFile (td->filenamePath.c_str (), File::FILE_OPEN_ALWAYS
                            | File::WRITE | symFlags);
           }
         catch (exception & e)
diff --git a/myserver/src/http_handler/wincgi/wincgi.cpp 
b/myserver/src/http_handler/wincgi/wincgi.cpp
index 8c1345c..ac5f9cb 100644
--- a/myserver/src/http_handler/wincgi/wincgi.cpp
+++ b/myserver/src/http_handler/wincgi/wincgi.cpp
@@ -112,7 +112,7 @@ int WinCgi::send (HttpThreadContext* td, const char* 
scriptpath,
         }
 
       /* The WinCGI protocol uses a .ini file to send data to the new process. 
 */
-      DataFileHandle.openFile (dataFilePath, File::FILE_CREATE_ALWAYS
+      DataFileHandle.openFile (dataFilePath, File::FILE_OPEN_ALWAYS
                                | File::WRITE);
 
       td->auxiliaryBuffer->setLength (0);
@@ -237,7 +237,7 @@ int WinCgi::send (HttpThreadContext* td, const char* 
scriptpath,
        *Create the out file.
        */
       if (! FilesUtility::nodeExists (outFilePath))
-        OutFileHandle.openFile (outFilePath, File::FILE_CREATE_ALWAYS
+        OutFileHandle.openFile (outFilePath, File::FILE_OPEN_ALWAYS
                                 | File::WRITE);
 
       OutFileHandle.close ();
diff --git a/myserver/src/log/log_manager.cpp b/myserver/src/log/log_manager.cpp
index 492485b..84223bc 100644
--- a/myserver/src/log/log_manager.cpp
+++ b/myserver/src/log/log_manager.cpp
@@ -32,7 +32,7 @@
  * \param ff The FiltersFactory object.
  * \param level The default level of logging.
  */
-LogManager::LogManager (FiltersFactory* ff,LoggingLevel level) : level (level)
+LogManager::LogManager (FiltersFactory* ff, LoggingLevel level) : level (level)
 {
   this->ff = ff;
   lsf = new LogStreamFactory ();
diff --git a/myserver/src/protocol/ftp/ftp.cpp 
b/myserver/src/protocol/ftp/ftp.cpp
index 3652a61..8d3b972 100644
--- a/myserver/src/protocol/ftp/ftp.cpp
+++ b/myserver/src/protocol/ftp/ftp.cpp
@@ -1168,7 +1168,7 @@ DEFINE_THREAD (ReceiveAsciiFile, pParam)
       if (pWt->m_bappend)
         flags = File::APPEND | File::WRITE;
       else
-        flags = File::FILE_CREATE_ALWAYS | File::WRITE;
+        flags = File::FILE_OPEN_ALWAYS | File::WRITE;
       flags |= areSymlinkAllowed (pWt->st) ? 0 : File::NO_FOLLOW_SYMLINK;
 
       if (file.openFile (pWt->m_sFilePath.c_str (), flags))
@@ -1368,7 +1368,7 @@ DEFINE_THREAD (ReceiveImageFile, pParam)
       if (pWt->m_bappend)
         flags = File::APPEND | File::WRITE;
       else
-        flags = File::FILE_CREATE_ALWAYS | File::WRITE;
+        flags = File::FILE_OPEN_ALWAYS | File::WRITE;
       flags |= areSymlinkAllowed (pWt->st) ? 0 : File::NO_FOLLOW_SYMLINK;
 
       if (file.openFile (pWt->m_sFilePath.c_str (), flags))
diff --git a/myserver/src/protocol/http/http_data_read.cpp 
b/myserver/src/protocol/http/http_data_read.cpp
index 85fd7d3..39c0f35 100644
--- a/myserver/src/protocol/http/http_data_read.cpp
+++ b/myserver/src/protocol/http/http_data_read.cpp
@@ -298,7 +298,7 @@ int HttpDataRead::readPostData (HttpThreadContext* td, int* 
httpRetCode)
    *Create the file that contains the posted data.
    *This data is the stdin file in the CGI.
    */
-  if (td->inputData.openFile (td->inputDataPath, File::FILE_CREATE_ALWAYS |
+  if (td->inputData.openFile (td->inputDataPath, File::FILE_OPEN_ALWAYS |
                             File::READ |
                             File::WRITE))
   {
diff --git a/myserver/tests/test_file.cpp b/myserver/tests/test_file.cpp
index 0330020..caf0ec7 100644
--- a/myserver/tests/test_file.cpp
+++ b/myserver/tests/test_file.cpp
@@ -53,7 +53,7 @@ class TestFile : public CppUnit::TestFixture
   {
    return  tfile->openFile (fname.c_str (), File::WRITE
                             | File::READ
-                            | File::FILE_CREATE_ALWAYS);
+                            | File::FILE_OPEN_ALWAYS);
   }
 public:
   void setUp ()
diff --git a/myserver/tests/test_log_manager.cpp 
b/myserver/tests/test_log_manager.cpp
index df1fca1..c8927bf 100644
--- a/myserver/tests/test_log_manager.cpp
+++ b/myserver/tests/test_log_manager.cpp
@@ -227,7 +227,7 @@ public:
     File f;
     char buf[64];
     u_long nbr;
-    LogStream* ls;
+    LogStream* ls = NULL;
     list<string> cs;
     list<string>::iterator it;
     try
@@ -250,6 +250,7 @@ public:
     gotMessage1.assign (buf);
 
     lm->get (this, "test", "file://foobar", &ls);
+    CPPUNIT_ASSERT (ls);
     cs = ls->getCycledStreams ();
     for (it = cs.begin (); it != cs.end (); it++)
       {
@@ -406,7 +407,7 @@ public:
     u_long nbr = 0;
     list<string> cs;
     list<string>::iterator it;
-    LogStream* ls;
+    LogStream* ls = NULL;
 
     try
       {
@@ -429,6 +430,7 @@ public:
     gzipDecomp[message1.size ()] = '\0';
     gotMessage1.assign (gzipDecomp);
     lm->get (this, "test", "file://fooc", &ls);
+    CPPUNIT_ASSERT (ls);
     cs = ls->getCycledStreams ();
     for (it = cs.begin (); it != cs.end (); it++)
       {
diff --git a/myserver/tests/test_membuf_file.cpp 
b/myserver/tests/test_membuf_file.cpp
index 997792d..4de8401 100644
--- a/myserver/tests/test_membuf_file.cpp
+++ b/myserver/tests/test_membuf_file.cpp
@@ -84,7 +84,7 @@ public:
     const char *file = "tmp.dat";
     CPPUNIT_ASSERT_EQUAL (tfile->openFile (file, File::WRITE
                                            | File::READ
-                                           | File::FILE_CREATE_ALWAYS), -1);
+                                           | File::FILE_OPEN_ALWAYS), -1);
   }
 
   void testWrite ()
diff --git a/myserver/tests/test_socket_pair.cpp 
b/myserver/tests/test_socket_pair.cpp
index 509e409..fdb1c7e 100644
--- a/myserver/tests/test_socket_pair.cpp
+++ b/myserver/tests/test_socket_pair.cpp
@@ -86,7 +86,7 @@ public:
 
     FilesUtility::temporaryFileName (0, fname);
     file.openFile (fname.c_str (), File::WRITE | File::READ
-                   | File::FILE_CREATE_ALWAYS);
+                   | File::FILE_OPEN_ALWAYS);
     file.writeToFile (outputBuffer, bsize, &nbw);
     file.seek (0);
 
diff --git a/myserver/tests/test_ssl_socket.cpp 
b/myserver/tests/test_ssl_socket.cpp
index f54d831..012ae3e 100644
--- a/myserver/tests/test_ssl_socket.cpp
+++ b/myserver/tests/test_ssl_socket.cpp
@@ -115,11 +115,11 @@ public:
     u_long nbw;
     File f;
 
-    f.openFile (TESTSERVERKEY,  File::WRITE | File::FILE_CREATE_ALWAYS);
+    f.openFile (TESTSERVERKEY,  File::WRITE | File::FILE_OPEN_ALWAYS);
     f.writeToFile (serverKey, strlen (serverKey), &nbw);
     f.close ();
 
-    f.openFile (TESTSERVERPEM,  File::WRITE | File::FILE_CREATE_ALWAYS);
+    f.openFile (TESTSERVERPEM,  File::WRITE | File::FILE_OPEN_ALWAYS);
     f.writeToFile (serverPem, strlen (serverPem), &nbw);
     f.close ();
   }
diff --git a/myserver/tests/test_xml_main_configuration.cpp 
b/myserver/tests/test_xml_main_configuration.cpp
index 4a25c46..229dcfb 100644
--- a/myserver/tests/test_xml_main_configuration.cpp
+++ b/myserver/tests/test_xml_main_configuration.cpp
@@ -49,7 +49,7 @@ public:
   {
     u_long nbw;
     xmlFile.openFile (XML_FILE, File::WRITE | File::READ
-                      | File::FILE_CREATE_ALWAYS);
+                      | File::FILE_OPEN_ALWAYS);
     CPPUNIT_ASSERT_EQUAL (xmlFile.write (XML_CONTENT, strlen (XML_CONTENT),
                                            &nbw), 0);
     CPPUNIT_ASSERT_EQUAL (nbw, static_cast<u_long> (strlen (XML_CONTENT)));
@@ -65,10 +65,25 @@ public:
   void testOpen ()
   {
     XmlMainConfiguration tmpXmlConf;
-
-    /* These files don't exist.  */
-    CPPUNIT_ASSERT (tmpXmlConf.open ("foo/bar/baz.xml"));
-    CPPUNIT_ASSERT (tmpXmlConf.open ("baz.xml"));
+    int exceptions = 0;
+    try
+      {
+        tmpXmlConf.open ("baz.xml");
+      }
+    catch (exception & e)
+      {
+        exceptions++;
+      }
+    try
+      {
+        tmpXmlConf.open ("foo/bar/baz.xml");
+      }
+    catch (exception & e)
+      {
+        exceptions++;
+      }
+
+    CPPUNIT_ASSERT_EQUAL (exceptions, 2);
 
     CPPUNIT_ASSERT_EQUAL (tmpXmlConf.open (XML_FILE), 0);
     CPPUNIT_ASSERT_EQUAL (tmpXmlConf.close (), 0);



commit 7c07c7987f544d60a9b29ed45be2a661f03582bc
Author: Giuseppe Scrivano <address@hidden>
Date:   Sun May 16 11:15:13 2010 +0200

    Use an enum for file opening flags.

diff --git a/myserver/include/base/file/file.h 
b/myserver/include/base/file/file.h
index df77f65..a267e4b 100644
--- a/myserver/include/base/file/file.h
+++ b/myserver/include/base/file/file.h
@@ -32,17 +32,20 @@ using namespace std;
 class File : public Stream
 {
 public:
-  static const u_long READ;
-  static const u_long WRITE;
-  static const u_long TEMPORARY_DELAYED;
-  static const u_long TEMPORARY;
-  static const u_long HIDDEN;
-  static const u_long FILE_OPEN_ALWAYS;
-  static const u_long OPEN_IF_EXISTS;
-  static const u_long APPEND;
-  static const u_long FILE_CREATE_ALWAYS;
-  static const u_long NO_INHERIT;
-  static const u_long NO_FOLLOW_SYMLINK;
+  enum
+    {
+      READ = (1 << 0),
+      WRITE = (1 << 1),
+      TEMPORARY = (1 << 2),
+      TEMPORARY_DELAYED = (1 << 3),
+      HIDDEN = (1 << 4),
+      FILE_OPEN_ALWAYS = (1 << 5),
+      OPEN_IF_EXISTS = (1 << 6),
+      APPEND = (1 << 7),
+      FILE_CREATE_ALWAYS = (1 << 8),
+      NO_INHERIT = (1 << 9),
+      NO_FOLLOW_SYMLINK = (1 << 10)
+    };
 
   File ();
   File (char *,int);
diff --git a/myserver/src/base/file/file.cpp b/myserver/src/base/file/file.cpp
index ceb65ac..530632b 100644
--- a/myserver/src/base/file/file.cpp
+++ b/myserver/src/base/file/file.cpp
@@ -50,19 +50,6 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
 
 using namespace std;
 
-const u_long File::READ = (1 << 0);
-const u_long File::WRITE = (1 << 1);
-const u_long File::TEMPORARY = (1 << 2);
-const u_long File::TEMPORARY_DELAYED = (1 << 3);
-const u_long File::HIDDEN = (1 << 4);
-const u_long File::FILE_OPEN_ALWAYS = (1 << 5);
-const u_long File::OPEN_IF_EXISTS = (1 << 6);
-const u_long File::APPEND = (1 << 7);
-const u_long File::FILE_CREATE_ALWAYS = (1 << 8);
-const u_long File::NO_INHERIT = (1 << 9);
-const u_long File::NO_FOLLOW_SYMLINK = (1 << 10);
-
-
 /*!
  *Costructor of the class.
  */

-----------------------------------------------------------------------

Summary of changes:
 myserver/include/base/file/file.h                 |   30 +++++----
 myserver/src/base/file/file.cpp                   |   73 ++++++---------------
 myserver/src/base/file/files_utility.cpp          |    2 +-
 myserver/src/http_handler/http_file/http_file.cpp |    2 +-
 myserver/src/http_handler/wincgi/wincgi.cpp       |    4 +-
 myserver/src/log/log_manager.cpp                  |    2 +-
 myserver/src/protocol/ftp/ftp.cpp                 |    4 +-
 myserver/src/protocol/http/http_data_read.cpp     |    2 +-
 myserver/tests/test_file.cpp                      |    2 +-
 myserver/tests/test_log_manager.cpp               |    6 +-
 myserver/tests/test_membuf_file.cpp               |    2 +-
 myserver/tests/test_socket_pair.cpp               |    2 +-
 myserver/tests/test_ssl_socket.cpp                |    4 +-
 myserver/tests/test_xml_main_configuration.cpp    |   25 ++++++--
 14 files changed, 72 insertions(+), 88 deletions(-)


hooks/post-receive
-- 
GNU MyServer



reply via email to

[Prev in Thread] Current Thread [Next in Thread]