(file) Return to FileSystem.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/FileSystem.cpp between version 1.6 and 1.87.10.2

version 1.6, 2001/04/07 12:01:18 version 1.87.10.2, 2013/09/01 11:06:00
Line 1 
Line 1 
 //BEGIN_LICENSE  //%LICENSE////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM  // Licensed to The Open Group (TOG) under one or more contributor license
   // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
   // this work for additional information regarding copyright ownership.
   // Each contributor licenses this file to you under the OpenPegasus Open
   // Source License; you may not use this file except in compliance with the
   // License.
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a // Permission is hereby granted, free of charge, to any person obtaining a
 // copy of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
Line 9 
Line 14 
 // and/or sell copies of the Software, and to permit persons to whom the // and/or sell copies of the Software, and to permit persons to whom the
 // Software is furnished to do so, subject to the following conditions: // Software is furnished to do so, subject to the following conditions:
 // //
 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  // The above copyright notice and this permission notice shall be included
 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  // in all copies or substantial portions of the Software.
 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL  
 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  
 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING  
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER  
 // DEALINGS IN THE SOFTWARE.  
 // //
 //END_LICENSE  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 //BEGIN_HISTORY  // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 // //
 // Author:  //////////////////////////////////////////////////////////////////////////
 // //
 // $Log$  //%/////////////////////////////////////////////////////////////////////////////
 // Revision 1.6  2001/04/07 12:01:18  karl  
 // remove namespace support  
 //  
 // Revision 1.5  2001/03/11 23:35:32  mike  
 // Ports to Linux  
 //  
 // Revision 1.3  2001/02/13 02:06:40  mike  
 // Added renameFile() method.  
 //  
 // Revision 1.2  2001/02/11 05:42:33  mike  
 // new  
 //  
 // Revision 1.1.1.1  2001/01/14 19:51:35  mike  
 // Pegasus import  
 //  
 //  
 //END_HISTORY  
  
   #include <iostream>
 #include <Pegasus/Common/Config.h> #include <Pegasus/Common/Config.h>
   #include <Pegasus/Common/System.h>
 #ifdef PEGASUS_OS_TYPE_WINDOWS  #include <Pegasus/Common/AutoPtr.h>
 # include <io.h>  #include <Executor/Match.h>
 # include <direct.h>  
 #else  
 # include <unistd.h>  
 # include <dirent.h>  
 #endif  
   
 #include <sys/stat.h>  
 #include <sys/types.h>  
 #include <cstdio>  
 #include "Destroyer.h"  
 #include "FileSystem.h" #include "FileSystem.h"
 #include "Dir.h" #include "Dir.h"
 //DEBUG ONLY  #ifndef PEGASUS_OS_TYPE_WINDOWS
 #include <iostream.h>  #include <pwd.h>
   #endif
 // ATTN-B: porting!  #include <Pegasus/Common/Tracer.h>
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
 #ifdef PEGASUS_OS_TYPE_WINDOWS  // Clone the path as a C String but discard trailing slash if any:
 static const int ACCESS_EXISTS = 0;  
 static const int ACCESS_WRITE = 2;  
 static const int ACCESS_READ = 4;  
 static const int ACCESS_READ_AND_WRITE = 6;  
 #endif  
  
 /** Clone the path as a C String but discard  static CString _clonePath(const String& path)
     trailing slash if any:  
 */  
 static char* _clonePath(const String& path)  
 { {
     char* p = path.allocateCString();      String clone = path;
   
     if (!*p)  
         return p;  
  
     char* last = p + path.getLength() - 1;      if (clone.size() && clone[clone.size()-1] == '/')
           clone.remove(clone.size()-1);
  
     if (*last == '/')      return clone.getCString();
         *last = '\0';  
   
     return p;  
 } }
  
 Boolean FileSystem::exists(const String& path) Boolean FileSystem::exists(const String& path)
 { {
     ArrayDestroyer<char> p(_clonePath(path));      return System::exists(_clonePath(path));
   
 #ifdef PEGASUS_OS_TYPE_WINDOWS  
     return _access(p.getPointer(), ACCESS_EXISTS) == 0;  
 #else  
     return access(p.getPointer(), F_OK) == 0;  
 #endif  
 } }
  
 Boolean FileSystem::getCurrentDirectory(String& path) Boolean FileSystem::getCurrentDirectory(String& path)
 { {
 #ifdef PEGASUS_OS_TYPE_WINDOWS      path.clear();
     char* tmp = _getcwd(NULL, 0);      char tmp[4096];
  
     if (!tmp)      if (!System::getCurrentDirectory(tmp, sizeof(tmp) - 1))
         return false;         return false;
  
     path.append(tmp);     path.append(tmp);
     delete [] tmp;  
 #else  
     char tmp[4096];  
   
     getcwd(tmp, sizeof(tmp));  
     path.append(tmp);  
 #endif  
     return true;     return true;
 } }
  
 Boolean FileSystem::existsIgnoreCase(const String& path, String& realPath)  Boolean FileSystem::existsNoCase(const String& path, String& realPath)
 { {
   #if !defined(PEGASUS_OS_VMS) && \
       !defined(PEGASUS_OS_TYPE_WINDOWS) && \
       !defined(PEGASUS_OS_DARWIN)
   
       // If a file exists that has the same case as the path parmater,
       // then we can bypass the expensive directory scanning below.
   
       if (FileSystem::exists(path))
       {
           realPath = path;
           return true;
       }
   
   #endif
   
     realPath.clear();     realPath.clear();
     ArrayDestroyer<char> destroyer(_clonePath(path));      CString cpath = _clonePath(path);
     char* p = destroyer.getPointer();      const char* p = cpath;
  
     char* dirPath;      const char* dirPath;
     char* fileName;      const char* fileName;
     char* slash = strrchr(p, '/');      char* slash = (char *) strrchr(p, '/');
  
     if (slash)     if (slash)
     {     {
         *slash = '\0';         *slash = '\0';
         fileName = slash + 1;         fileName = slash + 1;
         dirPath = p;         dirPath = p;
   
         if (*fileName == '\0')         if (*fileName == '\0')
             return false;             return false;
     }     }
Line 143 
Line 112 
         dirPath = ".";         dirPath = ".";
     }     }
  
   
     for (Dir dir(dirPath); dir.more(); dir.next())     for (Dir dir(dirPath); dir.more(); dir.next())
     {     {
 #ifdef PEGASUS_OS_TYPE_WINDOWS          if (System::strcasecmp(fileName, dir.getName()) == 0)
         if (stricmp(fileName, dir.getName()) == 0)  
 #else  
         if (strcasecmp(fileName, dir.getName()) == 0)  
 #endif  
         {         {
             if (strcmp(dirPath, ".") == 0)             if (strcmp(dirPath, ".") == 0)
                 realPath = dir.getName();                 realPath = dir.getName();
             else             else
             {             {
                 realPath = dirPath;                 realPath = dirPath;
                 realPath += '/';                  realPath.append('/');
                 realPath += dir.getName();                  realPath.append(dir.getName());
             }             }
             return true;             return true;
         }         }
Line 168 
Line 134 
  
 Boolean FileSystem::canRead(const String& path) Boolean FileSystem::canRead(const String& path)
 { {
     ArrayDestroyer<char> p(_clonePath(path));      return System::canRead(_clonePath(path));
   
 #ifdef PEGASUS_OS_TYPE_WINDOWS  
     return _access(p.getPointer(), ACCESS_READ) == 0;  
 #else  
     return access(p.getPointer(), R_OK) == 0;  
 #endif  
 } }
  
 Boolean FileSystem::canWrite(const String& path) Boolean FileSystem::canWrite(const String& path)
 { {
     ArrayDestroyer<char> p(_clonePath(path));      return System::canWrite(_clonePath(path));
   }
  
 #ifdef PEGASUS_OS_TYPE_WINDOWS  Boolean FileSystem::getFileSize(const String& path, Uint32& size)
     return _access(p.getPointer(), ACCESS_WRITE) == 0;  {
 #else      return System::getFileSize(_clonePath(path), size);
     return access(p.getPointer(), W_OK) == 0;  
 #endif  
 } }
  
 #if 0  Boolean FileSystem::removeFile(const String& path)
 // ATTN: not implemented for NT. But not used by Pegasus.  
 Boolean FileSystem::canExecute(const String& path)  
 { {
     ArrayDestroyer<char> p(_clonePath(path));      return System::removeFile(_clonePath(path));
     return access(p.getPointer(), X_OK) == 0;  
 } }
 #endif  
  
 Boolean FileSystem::isDirectory(const String& path)  void FileSystem::loadFileToMemory(
       Buffer& array,
       const String& fileName)
 { {
     ArrayDestroyer<char> p(_clonePath(path));      Uint32 fileSize;
  
     struct stat st;      if (!getFileSize(fileName, fileSize))
           throw CannotOpenFile(fileName);
  
 #ifdef PEGASUS_OS_TYPE_WINDOWS      FILE* fp = fopen(fileName.getCString(), "rb");
  
     if (stat(p.getPointer(), &st) != 0)      if (fp == NULL)
           throw CannotOpenFile(fileName);
   
       array.reserveCapacity(fileSize);
       char buffer[4096];
       size_t n;
   
       while ((n = fread(buffer, 1, sizeof(buffer), fp)) > 0)
           array.append(buffer, static_cast<Uint32>(n));
   
       fclose(fp);
   }
   
   Boolean FileSystem::compareFiles(
       const String& path1,
       const String& path2)
   {
       Uint32 fileSize1;
   
       if (!getFileSize(path1, fileSize1))
           throw CannotOpenFile(path1);
   
       Uint32 fileSize2;
   
       if (!getFileSize(path2, fileSize2))
           throw CannotOpenFile(path2);
   
       if (fileSize1 != fileSize2)
         return false;         return false;
  
     Boolean result = (st.st_mode & _S_IFDIR) != 0;      FILE* fp1 = fopen(path1.getCString(), "rb");
     return result;  
  
 #else      if (fp1 == NULL)
           throw CannotOpenFile(path1);
   
       FILE* fp2 = fopen(path2.getCString(), "rb");
  
     if (stat(p.getPointer(), &st) != 0)      if (fp2 == NULL)
       {
           fclose(fp1);
           throw CannotOpenFile(path2);
       }
   
       int c1;
       int c2;
   
       while ((c1 = fgetc(fp1)) != EOF && (c2 = fgetc(fp2)) != EOF)
       {
           if (c1 != c2)
           {
               fclose(fp1);
               fclose(fp2);
         return false;         return false;
           }
       }
   
       fclose(fp1);
       fclose(fp2);
       return true;
   }
  
     Boolean result = S_ISDIR(st.st_mode);  Boolean FileSystem::renameFile(
     return result;      const String& oldPath,
       const String& newPath)
   {
       return System::renameFile(oldPath.getCString(), newPath.getCString());
   }
  
 #endif  Boolean FileSystem::copyFile(
       const String& fromPath,
       const String& toPath)
   {
       return System::copyFile(fromPath.getCString(), toPath.getCString());
 } }
  
 Boolean FileSystem::changeDirectory(const String& path)  Boolean FileSystem::openNoCase(PEGASUS_STD(ifstream)& is, const String& path)
 { {
     ArrayDestroyer<char> p(_clonePath(path));      String realPath;
     return chdir(p.getPointer()) == 0;  
       if (!existsNoCase(path, realPath))
           return false;
   
       is.open(_clonePath(realPath) PEGASUS_IOS_BINARY);
   
       return !!is;
 } }
  
 Boolean FileSystem::makeDirectory(const String& path)  Boolean FileSystem::openNoCase(
       PEGASUS_STD(fstream)& fs,
       const String& path,
       int mode)
 { {
     ArrayDestroyer<char> p(_clonePath(path));      String realPath;
 #ifdef PEGASUS_OS_TYPE_WINDOWS  
     return _mkdir(p.getPointer()) == 0;      if (!existsNoCase(path, realPath))
           return false;
   #if defined(__GNUC__) && GCC_VERSION >= 30200
       fs.open(_clonePath(realPath), PEGASUS_STD(ios_base::openmode)(mode));
 #else #else
     return mkdir(p.getPointer(), 0777) == 0;      fs.open(_clonePath(realPath), mode);
 #endif #endif
       return !!fs;
 } }
  
 Boolean FileSystem::getFileSize(const String& path, Uint32& size)  Boolean FileSystem::isDirectory(const String& path)
 { {
     struct stat st;      return System::isDirectory(_clonePath(path));
   }
     ArrayDestroyer<char> p(_clonePath(path));  
  
     if (stat(p.getPointer(), &st) != 0)  Boolean FileSystem::changeDirectory(const String& path)
         return false;  {
       return System::changeDirectory(_clonePath(path));
   }
  
     size = st.st_size;  Boolean FileSystem::makeDirectory(const String& path)
     return true;  {
       return System::makeDirectory(_clonePath(path));
 } }
  
 Boolean FileSystem::removeDirectory(const String& path) Boolean FileSystem::removeDirectory(const String& path)
 { {
     ArrayDestroyer<char> p(_clonePath(path));      return System::removeDirectory(_clonePath(path));
     return rmdir(p.getPointer()) == 0;  
 } }
  
 Boolean FileSystem::removeDirectoryHier(const String& path) Boolean FileSystem::removeDirectoryHier(const String& path)
 { {
     // ATTN: Mike - remove following cmts and compile      Array<String> fileList;
     cout << "DEBUG RMDIR " << path << endl;  
  
 // Even the following does not compile      // Get contents of current directory
     // the ostream operator does not work  
     // ATTN: Mike: remove following cmts and compile  
     // String teststring;  
     // teststring.append("abc");  
     // cout << teststring;  
  
     // Get list of files in the Directory  
     Array<String> fileList;  
     if (!FileSystem::getDirectoryContents(path,fileList))     if (!FileSystem::getDirectoryContents(path,fileList))
         return false;         return false;
  
     // ATTN: Since not tested.  Following is bypass      // for files-in-directory, delete or recall removedir
   
       for (Uint32 i = 0, n = fileList.size(); i < n; i++)
       {
           String newPath = path;   // extend path to subdir
           newPath.append("/");
           newPath.append(fileList[i]);
   
           if (FileSystem::isDirectory(newPath))
           {
               // Recall ourselves with extended path
               if (!FileSystem::removeDirectoryHier(newPath))
                   return false;
           }
   
           else
           {
             if (!FileSystem::removeFile(newPath))
                   return false;
           }
       }
   
       return removeDirectory(path);
   }
   
   //
   //  Get the file list in the directory into the
   //  array of strings provided
   //  @return The function should return false under these circumstances:
   //
   //
   //  1. The directory does not exist.
   //  2. The file exists but is not a directory.
   //  3. The directory is inaccessible.
   //
   //
   Boolean FileSystem::getDirectoryContents(
       const String& path,
       Array<String>& paths)
   {
       paths.clear();
   
       try
       {
           for (Dir dir(path); dir.more(); dir.next())
           {
               String name = dir.getName();
   
               if (String::equal(name, ".") || String::equal(name, ".."))
                   continue;
   
               paths.append(name);
           }
     return true;     return true;
       }
  
     // for files-in-directory, delete or recall removedir      // Catch the Dir exception
     // Do not yet test for boolean returns on the removes      catch (CannotOpenDirectory&)
     // ATTN Diagnostics still installed ks.      {
     for (Uint32 i = 0, n = fileList.getSize(); i < n; i++)          return false;
     {      }
         if (FileSystem::isDirectory(fileList[i])){  
             //cout << "DEBUG RMDIR Next " << fileList[i] << endl;  
             FileSystem::removeDirectoryHier(fileList[i]);  
         }         }
  
         else{  Boolean FileSystem::isDirectoryEmpty(const String& path)
             //cout << "DEBUG RMFIL " << fileList[i] <<endl;  {
             removeFile(fileList[i]);      for (Dir dir(path); dir.more(); dir.next())
       {
           const char* name = dir.getName();
   
           if (strcmp(name, ".") != 0 && strcmp(name, "..") != 0)
               return false;
         }         }
  
       return true;
   }
   
   void FileSystem::translateSlashes(String& path)
   {
       for (Uint32 i = 0; i < path.size(); i++)
       {
           if (path[i] == '\\')
               path[i] = '/';
     }     }
     return removeDirectory(path);  
 } }
  
 Boolean FileSystem::removeFile(const String& path)  // Return the just the base name from the path.
   String FileSystem::extractFileName(const String& path)
 { {
     ArrayDestroyer<char> p(_clonePath(path));      AutoArrayPtr<char> p_path(new char[path.size() + 1]);
     return unlink(p.getPointer()) == 0;      String basename = System::extract_file_name(
           (const char*)path.getCString(), p_path.get());
   
       return basename;
 } }
  
 void FileSystem::loadFileToMemory(  // Return just the path to the file or directory into path
     Array<Sint8>& array,  String FileSystem::extractFilePath(const String& path)
     const String& fileName)  
 { {
     Uint32 fileSize;      AutoArrayPtr<char> p_path(new char[path.size() + 1]);
       String newpath = System::extract_file_path(
           (const char*)path.getCString(), p_path.get());
  
     if (!getFileSize(fileName, fileSize))      return newpath;
         throw CannotOpenFile(fileName);  }
  
     char* tmp = fileName.allocateCString();  // Changes file permissions on the given file.
     FILE* fp = fopen(tmp, "rb");  Boolean FileSystem::changeFilePermissions(const String& path, mode_t mode)
     delete [] tmp;  {
       CString tempPath = path.getCString();
  
     if (fp == NULL)      return System::changeFilePermissions(tempPath, mode);
         throw CannotOpenFile(fileName);  }
  
     array.reserve(fileSize);  String FileSystem::getAbsoluteFileName(
     char buffer[4096];      const String& paths,
     size_t n;      const String& filename)
   {
       Uint32 pos = 0;
       Uint32 token = 0;
       String path;
       String root;
       String tempPath = paths;
  
     while ((n = fread(buffer, 1, sizeof(buffer), fp)) > 0)      do
         array.append(buffer, n);      {
           if ((pos = tempPath.find(FileSystem::getPathDelimiter())) ==
               PEG_NOT_FOUND)
           {
               pos = tempPath.size();
               token = 0;
           }
           else
           {
               token = 1;
           }
           path = tempPath.subString(0, pos);
           tempPath.remove(0,pos+token);
           if (FileSystem::exists(path + "/" + filename) == true)
           {
               root = path + "/" + filename;
               break;
           }
           else
           {
               //  cout << "File does not exist.\n";
           }
       } while (tempPath.size() > 0);
  
     fclose(fp);      return root;
 } }
  
 Boolean FileSystem::compare(  #ifdef PEGASUS_ENABLE_PROTOCOL_WEB
     const String& fileName1,  
     const String& fileName2)  String FileSystem::getAbsoluteFileName(
       const String& filename)
 { {
     Uint32 fileSize1;      char resolvedName[PATH_MAX+1];
       /*
        * ReturnValue:
        *    1) Upon successful completion, realpath() shall return a pointer to
        *        the buffer containing the resolved name. Otherwise, realpath()
        *        shall return a null pointer and set errno to indicate the error.
        *    2) If the resolved_name argument is a null pointer, the pointer
        *        returned by realpath() can be passed to free().
        *    3) If the resolved_name argument is not a null pointer and the
        *        realpath() function fails, the contents of the buffer pointed to
        *        by resolved_name are undefined.
        */
       char* result = realpath(filename.getCString(), resolvedName);
       if (!result)
       {// failed, resolvedName is undefined
           return String("");
       }
       return String(result);
   }
  
     if (!getFileSize(fileName1, fileSize1))  #endif
         throw CannotOpenFile(fileName1);  
  
     Uint32 fileSize2;  String FileSystem::buildLibraryFileName(const String &libraryName)
   {
       String fileName;
  
     if (!getFileSize(fileName2, fileSize2))      //
         throw CannotOpenFile(fileName2);      // Add the necessary prefix and suffix to convert the library name to its
       // corresponding file name.
       //
   #if defined(PEGASUS_OS_TYPE_WINDOWS)
       fileName = libraryName + String(".dll");
   #else
       fileName = String("lib") + libraryName + getDynamicLibraryExtension();
   #endif
       return fileName;
   }
  
     if (fileSize1 != fileSize2)  String FileSystem::getDynamicLibraryExtension()
         return false;  {
   #if defined(PEGASUS_OS_TYPE_WINDOWS)
       return String(".dll");
   #elif defined(PEGASUS_PLATFORM_HPUX_PARISC_ACC) || \
       defined (PEGASUS_PLATFORM_HPUX_PARISC_GNU)
       return String(".sl");
   #elif defined(PEGASUS_OS_DARWIN)
       return String(".dylib");
   #elif defined(PEGASUS_OS_VMS)
       return String(".exe");
   #elif defined(PEGASUS_PLATFORM_ZOS_ZSERIES64_IBM)
       return String("64.so");
   #else
       return String(".so");
   #endif
   }
  
     char* tmp1 = fileName1.allocateCString();  Boolean GetLine(PEGASUS_STD(istream)& is, Buffer& line)
     FILE* fp1 = fopen(tmp1, "rb");  {
     delete [] tmp1;      const Uint32 buffersize = 1024;
       Uint32 gcount = 0;
  
     if (fp1 == NULL)      line.clear();
         throw CannotOpenFile(fileName1);  
       // Read the input line in chunks.  A non-full buffer indicates the end of
       // the line has been reached.
       do
       {
           char input[buffersize];
  
     char* tmp2 = fileName2.allocateCString();          // This reads up to buffersize-1 char, but stops before consuming
     FILE* fp2 = fopen(tmp2, "rb");          // a newline character ('\n').
     delete [] tmp2;          is.get(input, buffersize);
  
     if (fp2 == NULL)          gcount = (Uint32)is.gcount();
           line.append(input, gcount);
   
           if (is.rdstate() & PEGASUS_STD(istream)::failbit)
     {     {
         fclose(fp1);              // It is okay if we encounter the newline character without reading
         throw CannotOpenFile(fileName2);              // data.
               is.clear();
               break;
     }     }
       } while (gcount == buffersize-1);
  
     int c1;      if (!is.eof())
     int c2;      {
           // we need to consume the '\n', because get() doesn't
           char c = 0;
           is.get(c);
       }
  
     while ((c1 = fgetc(fp1)) != EOF && (c2 = fgetc(fp2)) != EOF)      return !!is;
   }
   
   //
   // changes the file owner to one specified
   //
   Boolean FileSystem::changeFileOwner(
       const String& fileName,
       const String& userName)
     {     {
         if (c1 != c2)  #if defined(PEGASUS_OS_TYPE_WINDOWS)
   
       return true;
   
   #else
   
       PEG_METHOD_ENTER(TRC_AUTHENTICATION, "FileSystem::changeFileOwner()");
   
       struct passwd* userPasswd;
   #if defined(PEGASUS_OS_SOLARIS) || \
       defined(PEGASUS_OS_HPUX) || \
       defined(PEGASUS_OS_LINUX) || \
       defined (PEGASUS_OS_VMS) || \
       defined (PEGASUS_OS_AIX)
   
       const unsigned int PWD_BUFF_SIZE = 1024;
       struct passwd pwd;
       char pwdBuffer[PWD_BUFF_SIZE];
   
       if (getpwnam_r(userName.getCString(), &pwd, pwdBuffer, PWD_BUFF_SIZE,
                     &userPasswd) != 0)
         {         {
             fclose(fp1);          userPasswd = (struct passwd*)NULL;
             fclose(fp2);      }
   
   #else
   
       userPasswd = getpwnam(userName.getCString());
   #endif
   
       if (userPasswd  == NULL)
       {
           PEG_METHOD_EXIT();
             return false;             return false;
         }         }
   
       Sint32 ret = chown(
           fileName.getCString(), userPasswd->pw_uid, userPasswd->pw_gid);
   
       if (ret == -1)
       {
           PEG_METHOD_EXIT();
           return false;
     }     }
  
     fclose(fp1);      PEG_METHOD_EXIT();
     fclose(fp2);  
     return true;     return true;
   #endif
 } }
 /*  Get the file list in the directory into the  
     array of strings provided  
     @return The function should return false under these circumstances:  
  
   #if defined(PEGASUS_OS_HPUX)
   void FileSystem::syncWithDirectoryUpdates(PEGASUS_STD(fstream)& fs)
   {
     #if defined (PEGASUS_PLATFORM_HPUX_IA64_GNU) || \
       defined (PEGASUS_PLATFORM_HPUX_PARISC_GNU)
       // Writes the data from the iostream buffers to the OS buffers
       fs.flush();
       // Writes the data from the OS buffers to the disk
       fs.rdbuf()->pubsync();
       #else
       // Writes the data from the iostream buffers to the OS buffers
       fs.flush();
       // Writes the data from the OS buffers to the disk
       fsync(fs.rdbuf()->fd());
       #endif
   }
   #else
   void FileSystem::syncWithDirectoryUpdates(PEGASUS_STD(fstream)&)
   {
       //Not HP-UX, do nothing (compiler will remove this fct on optimization)
   }
   #endif
  
     1. The directory does not exist.  Boolean FileSystem::glob(
     2. The file exists but is not a directory.  
     3. The directory is inaccessible.  
   
 */  
 Boolean FileSystem::getDirectoryContents(  
     const String& path,     const String& path,
     Array<String>& paths)      const String& pattern_,
       Array<String>& filenames)
 { {
     // This may be just extra fluff but added anyway      filenames.clear();
     if (!FileSystem::isDirectory(path))  
         return false;  
  
     paths.clear();  
     try     try
     {     {
           CString pattern(pattern_.getCString());
   
         for (Dir dir(path); dir.more(); dir.next())         for (Dir dir(path); dir.more(); dir.next())
         {         {
             String name = dir.getName();              const char* name = dir.getName();
  
             if (String::equal(name, ".") || String::equal(name, ".."))              if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
                 continue;                 continue;
             // cout << "DEBUG DIR = " << dir.getName() << endl;  
             paths.append(name);              if (Match(pattern, name) == 0)
                   filenames.append(name);
         }         }
         return true;  
     }     }
   
     // Catch the Dir exception  
     catch(CannotOpenDirectory&)     catch(CannotOpenDirectory&)
     {     {
         return false;         return false;
     }     }
  
 }      return true;
   
 Boolean FileSystem::renameFile(  
     const String& oldFileName,  
     const String& newFileName)  
 {  
     ArrayDestroyer<char> p(oldFileName.allocateCString());  
     ArrayDestroyer<char> q(newFileName.allocateCString());  
   
 #ifdef PEGASUS_OS_TYPE_WINDOWS  
     return rename(p.getPointer(), q.getPointer()) == 0;  
 #else  
     if (link(p.getPointer(), q.getPointer()) != 0)  
         return false;  
   
     return unlink(p.getPointer()) == 0;  
 #endif  
 } }
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.6  
changed lines
  Added in v.1.87.10.2

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2