(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.11 and 1.71.6.3

version 1.11, 2001/04/08 20:29:41 version 1.71.6.3, 2007/09/12 16:18:48
Line 1 
Line 1 
 //BEGIN_LICENSE  //%2006////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM  // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
   // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
   // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation, The Open Group.
   // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; Symantec Corporation; The Open Group.
   //
   // Permission is hereby granted, free of charge, to any person obtaining a copy
   // of this software and associated documentation files (the "Software"), to
   // deal in the Software without restriction, including without limitation the
   // rights to use, copy, modify, merge, publish, distribute, sublicense, 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:
   //
   // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
   // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
   // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 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.
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a  //==============================================================================
 // copy of this software and associated documentation files (the "Software"),  
 // to deal in the Software without restriction, including without limitation  
 // the rights to use, copy, modify, merge, publish, distribute, sublicense,  
 // 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:  
 // //
 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 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.  
 //  
 //END_LICENSE  
 //BEGIN_HISTORY  
 //  
 // Author:  
 //  
 // $Log$  
 // Revision 1.11  2001/04/08 20:29:41  mike  
 // Added std:: before cout and endl  
 //  
 // Revision 1.10  2001/04/08 20:28:27  karl  
 // test  
 //  
 // Revision 1.9  2001/04/08 19:56:38  karl  
 // Test version  
 //  
 // Revision 1.8  2001/04/08 19:20:04  mike  
 // more TCP work  
 //  
 // Revision 1.7  2001/04/08 01:13:21  mike  
 // Changed "ConstCIM" to "CIMConst"  
 //  
 // 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 <cstdio>
 #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  #if !defined(PEGASUS_OS_TYPE_WINDOWS) && !defined(PEGASUS_OS_VXWORKS)
 #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)
 { {
     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 155 
Line 99 
         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 180 
Line 121 
  
 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;
           }
       }
  
     Boolean result = S_ISDIR(st.st_mode);      fclose(fp1);
     return result;      fclose(fp2);
       return true;
   }
  
 #endif  Boolean FileSystem::renameFile(
       const String& oldPath,
       const String& newPath)
   {
       return System::renameFile(oldPath.getCString(), newPath.getCString());
 } }
  
 Boolean FileSystem::changeDirectory(const String& path)  Boolean FileSystem::copyFile(
       const String& fromPath,
       const String& toPath)
 { {
     ArrayDestroyer<char> p(_clonePath(path));      return System::copyFile(fromPath.getCString(), toPath.getCString());
     return chdir(p.getPointer()) == 0;  
 } }
  
 Boolean FileSystem::makeDirectory(const String& path)  Boolean FileSystem::openNoCase(PEGASUS_STD(ifstream)& is, const String& path)
   {
       String realPath;
   
       if (!existsNoCase(path, realPath))
           return false;
   
       is.open(_clonePath(realPath) PEGASUS_IOS_BINARY);
   
       return !!is;
   }
   
   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)
 { {
     String saveCwd;  
     FileSystem::getCurrentDirectory(saveCwd);  
   
     Array<String> fileList;     Array<String> fileList;
  
       // Get contents of current directory
   
     if (!FileSystem::getDirectoryContents(path,fileList))     if (!FileSystem::getDirectoryContents(path,fileList))
         return false;         return false;
  
     FileSystem::changeDirectory(path);  
   
     // for files-in-directory, delete or recall removedir     // for files-in-directory, delete or recall removedir
     // Do not yet test for boolean returns on the removes  
     for (Uint32 i = 0, n = fileList.getSize(); i < n; i++)      for (Uint32 i = 0, n = fileList.size(); i < n; i++)
     {     {
         // ATTN: Debug code here          String newPath = path;   // extend path to subdir
         ArrayDestroyer<char> q(_clonePath(fileList[i]));          newPath.append("/");
           newPath.append(fileList[i]);
  
         if (FileSystem::isDirectory(fileList[i])){          if (FileSystem::isDirectory(newPath))
             FileSystem::removeDirectoryHier(fileList[i]);          {
               // Recall ourselves with extended path
               if (!FileSystem::removeDirectoryHier(newPath))
                   return false;
         }         }
  
         else{          else
             // ATTN: Mike the second is the problem.          {
             std::cout << "DEBUG RMFIL " << q.getPointer() <<std::endl;            if (!FileSystem::removeFile(newPath))
             std::cout << "DEBUG RMFIL " << fileList[i] <<std::endl;                  return false;
             removeFile(fileList[i]);  
         }         }
     }     }
  
     FileSystem::changeDirectory(saveCwd);  
     return removeDirectory(path);     return removeDirectory(path);
 } }
  
 Boolean FileSystem::removeFile(const String& 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;
       }
   
       // Catch the Dir exception
       catch (CannotOpenDirectory&)
 { {
     ArrayDestroyer<char> p(_clonePath(path));          return false;
     return unlink(p.getPointer()) == 0;      }
 } }
  
 void FileSystem::loadFileToMemory(  Boolean FileSystem::isDirectoryEmpty(const String& path)
     Array<Sint8>& array,  
     const String& fileName)  
 { {
     Uint32 fileSize;      for (Dir dir(path); dir.more(); dir.next())
       {
           const char* name = dir.getName();
  
     if (!getFileSize(fileName, fileSize))          if (strcmp(name, ".") != 0 && strcmp(name, "..") != 0)
         throw CannotOpenFile(fileName);              return false;
       }
  
     char* tmp = fileName.allocateCString();      return true;
     FILE* fp = fopen(tmp, "rb");  }
     delete [] tmp;  
  
     if (fp == NULL)  void FileSystem::translateSlashes(String& path)
         throw CannotOpenFile(fileName);  {
       for (Uint32 i = 0; i < path.size(); i++)
       {
           if (path[i] == '\\')
               path[i] = '/';
       }
   }
  
     array.reserve(fileSize);  // Return the just the base name from the path.
     char buffer[4096];  String FileSystem::extractFileName(const String& path)
     size_t n;  {
       AutoArrayPtr<char> p_path(new char[path.size() + 1]);
       String basename = System::extract_file_name(
           (const char*)path.getCString(), p_path.get());
  
     while ((n = fread(buffer, 1, sizeof(buffer), fp)) > 0)      return basename;
         array.append(buffer, n);  }
  
     fclose(fp);  // Return just the path to the file or directory into path
   String FileSystem::extractFilePath(const String& path)
   {
       AutoArrayPtr<char> p_path(new char[path.size() + 1]);
       String newpath = System::extract_file_path(
           (const char*)path.getCString(), p_path.get());
   
       return newpath;
 } }
  
 Boolean FileSystem::compare(  // Changes file permissions on the given file.
     const String& fileName1,  Boolean FileSystem::changeFilePermissions(const String& path, mode_t mode)
     const String& fileName2)  
 { {
     Uint32 fileSize1;      CString tempPath = path.getCString();
  
     if (!getFileSize(fileName1, fileSize1))      return System::changeFilePermissions(tempPath, mode);
         throw CannotOpenFile(fileName1);  }
  
     Uint32 fileSize2;  String FileSystem::getAbsoluteFileName(
       const String& paths,
       const String& filename)
   {
       Uint32 pos = 0;
       Uint32 token = 0;
       String path;
       String root;
       String tempPath = paths;
  
     if (!getFileSize(fileName2, fileSize2))      do
         throw CannotOpenFile(fileName2);      {
           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);
  
     if (fileSize1 != fileSize2)      return root;
         return false;  }
  
     char* tmp1 = fileName1.allocateCString();  String FileSystem::buildLibraryFileName(const String &libraryName)
     FILE* fp1 = fopen(tmp1, "rb");  {
     delete [] tmp1;      String fileName;
  
     if (fp1 == NULL)      //
         throw CannotOpenFile(fileName1);      // 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");
   #elif defined(PEGASUS_PLATFORM_HPUX_PARISC_ACC)
       fileName = String("lib") + libraryName + String(".sl");
   #elif defined(PEGASUS_OS_DARWIN)
       fileName = String("lib") + libraryName + String(".dylib");
   #elif defined(PEGASUS_OS_VMS)
       fileName = String("lib") + libraryName;
   #else
       fileName = String("lib") + libraryName + String(".so");
   #endif
  
     char* tmp2 = fileName2.allocateCString();      return fileName;
     FILE* fp2 = fopen(tmp2, "rb");  }
     delete [] tmp2;  
  
     if (fp2 == NULL)  
   Boolean GetLine(PEGASUS_STD(istream)& is, String& line)
     {     {
         fclose(fp1);      line.clear();
         throw CannotOpenFile(fileName2);  
       Boolean gotChar = false;
   #ifdef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM
       char input[1000];
       is.getline(input,1000);
       line.assign(input);
   
       gotChar = !(is.rdstate() & PEGASUS_STD(istream)::failbit);
   #else
       char c;
   
       while (is.get(c))
       {
           gotChar = true;
   
           if (c == '\n')
               break;
   
           line.append(c);
     }     }
   #endif
  
     int c1;      return gotChar;
     int c2;  }
  
     while ((c1 = fgetc(fp1)) != EOF && (c2 = fgetc(fp2)) != EOF)  //==============================================================================
   //
   // PEGASUS_OS_VXWORKS
   //
   //==============================================================================
   
   #if defined(PEGASUS_OS_VXWORKS)
   
   Boolean FileSystem::changeFileOwner(
       const String& fileName,
       const String& userName)
     {     {
         if (c1 != c2)      // ATTN-MEB: revisit!
   
       if (userName == PEGASUS_VXWORKS_USER)
           return true;
   
       return false;
   }
   
   #endif /* defined(PEGASUS_OS_VXWORKS) */
   
   //==============================================================================
   //
   // !PEGASUS_OS_VXWORKS
   //
   //==============================================================================
   
   #if !defined(PEGASUS_OS_VXWORKS)
   
   //
   // changes the file owner to one specified
   //
   Boolean FileSystem::changeFileOwner(
       const String& fileName,
       const String& userName)
         {         {
             fclose(fp1);  #if defined(PEGASUS_OS_TYPE_WINDOWS)
             fclose(fp2);  
       return true;
   
   #else
   
       PEG_METHOD_ENTER(TRC_AUTHENTICATION, "FileSystem::changeFileOwner()");
   
       struct passwd* userPasswd;
   #if defined(PEGASUS_PLATFORM_SOLARIS_SPARC_CC) || \
       defined(PEGASUS_OS_HPUX) || \
       defined (PEGASUS_OS_LINUX)
   
       const unsigned int PWD_BUFF_SIZE = 1024;
       struct passwd pwd;
       struct passwd *result;
       char pwdBuffer[PWD_BUFF_SIZE];
   
       if (getpwnam_r(userName.getCString(), &pwd, pwdBuffer, PWD_BUFF_SIZE,
                     &userPasswd) != 0)
       {
           userPasswd = (struct passwd*)NULL;
       }
   
   #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:  
  
   #endif /* !defined(PEGASUS_OS_VXWORKS) */
  
     1. The directory does not exist.  void FileSystem::syncWithDirectoryUpdates(PEGASUS_STD(fstream)& fs)
     2. The file exists but is not a directory.  {
     3. The directory is inaccessible.  #if defined(PEGASUS_OS_HPUX)
       // 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
   }
  
 */  Boolean FileSystem::glob(
 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;
             paths.append(name);  
               if (Match(name, pattern) == 0)
                   filenames.append(name);
         }         }
         return true;  
     }     }
       catch (...)
     // Catch the Dir exception  
     catch(CannotOpenDirectory&)  
     {     {
         return false;         return false;
     }     }
  
       return true;
 } }
  
 Boolean FileSystem::renameFile(  Boolean FileSystem::removeMatchingFiles(
     const String& oldFileName,      const String& path, const String& pattern)
     const String& newFileName)  
 { {
     ArrayDestroyer<char> p(oldFileName.allocateCString());  
     ArrayDestroyer<char> q(newFileName.allocateCString());  
  
 #ifdef PEGASUS_OS_TYPE_WINDOWS      Array<String> filenames;
     return rename(p.getPointer(), q.getPointer()) == 0;  
 #else      if (!FileSystem::glob(path, pattern, filenames))
     if (link(p.getPointer(), q.getPointer()) != 0)  
         return false;         return false;
  
     return unlink(p.getPointer()) == 0;      for (size_t i = 0; i < filenames.size(); i++)
 #endif      {
           if (!FileSystem::removeFile(filenames[i]))
               return false;
       }
   
       return true;
 } }
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.11  
changed lines
  Added in v.1.71.6.3

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2