version 1.15.2.1, 2001/10/10 15:39:06
|
version 1.50, 2008/05/02 21:05:30
|
|
|
//%///////////////////////////////////////////////////////////////////////////// |
//%2006//////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001 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 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
// of this software and associated documentation files (the "Software"), to | // of this software and associated documentation files (the "Software"), to |
|
|
// | // |
//============================================================================== | //============================================================================== |
// | // |
// Author: Mike Brasher (mbrasher@bmc.com) |
|
// |
|
// Modified By: |
|
// |
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
#ifndef Pegasus_FileSystem_h | #ifndef Pegasus_FileSystem_h |
|
|
| |
#include <Pegasus/Common/Config.h> | #include <Pegasus/Common/Config.h> |
#include <Pegasus/Common/String.h> | #include <Pegasus/Common/String.h> |
#include <Pegasus/Common/Array.h> |
#include <Pegasus/Common/ArrayInternal.h> |
#include <Pegasus/Common/Exception.h> |
#include <Pegasus/Common/InternalException.h> |
|
#include <Pegasus/Common/System.h> |
|
#include <Pegasus/Common/Linkage.h> |
#include <fstream> | #include <fstream> |
|
#include <cstdio> |
|
#include <Pegasus/Common/Buffer.h> |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
|
|
*/ | */ |
static Boolean removeFileNoCase(const String& path); | static Boolean removeFileNoCase(const String& path); |
| |
|
/** Produces an array of filenames that match the given pattern under |
|
the directory given by path. The pattern is limited to asterisks |
|
only. Examples: "*.txt", "hello*world.c". Returns true on success. |
|
Return false if the base diretory does not exist or cannot be |
|
accessed. |
|
*/ |
|
static Boolean glob( |
|
const String& path, |
|
const String& pattern, |
|
Array<String>& filenames); |
|
|
/** Loads contents of the file into the array. Note that the file is | /** Loads contents of the file into the array. Note that the file is |
opened using binary mode (newline sequences are not expanded to | opened using binary mode (newline sequences are not expanded to |
carriage-return-line-feed sequences on Windows). | carriage-return-line-feed sequences on Windows). |
|
|
@exception CannotOpenFile | @exception CannotOpenFile |
*/ | */ |
static void loadFileToMemory( | static void loadFileToMemory( |
Array<Sint8>& array, |
Buffer& array, |
const String& fileName); | const String& fileName); |
| |
/** Determines whether two files have exactly the same content. | /** Determines whether two files have exactly the same content. |
|
|
const String& oldPath, | const String& oldPath, |
const String& newPath); | const String& newPath); |
| |
|
/** Same as rename file except that the case of the file referred to |
|
by oldPath is ignored. |
|
*/ |
|
static Boolean renameFileNoCase( |
|
const String& oldPath, |
|
const String& newPath); |
|
|
|
/** Copy a file. |
|
@param fromPath name of existing file. |
|
@param toPath name of new file. |
|
@return true on success. |
|
*/ |
|
static Boolean copyFile( |
|
const String& fromPath, |
|
const String& toPath); |
|
|
/** Opens a file and ignores the case of the file. Note that the file | /** Opens a file and ignores the case of the file. Note that the file |
will be opend in binary mode (no translation of carriage-return-line- | will be opend in binary mode (no translation of carriage-return-line- |
feed sequences on Windows). | feed sequences on Windows). |
|
|
@param path path of file to be opened. | @param path path of file to be opened. |
@return true on success. | @return true on success. |
*/ | */ |
Boolean openNoCase(PEGASUS_STD(ifstream)& is, const String& path); |
static Boolean openNoCase(PEGASUS_STD(ifstream)& is, const String& path); |
|
|
|
/** Opens a file and ignores the case of the file. Note that the file |
|
open mode of the file must be passed in. |
|
@param os file stream to be opend. |
|
@param path path of file to be opened. |
|
@param mode mode to open the file in. |
|
@return true on success. |
|
*/ |
|
static Boolean openNoCase( |
|
PEGASUS_STD(fstream)& fs, |
|
const String& path, |
|
int mode); |
| |
/** Determines whether the path refers to a directory. | /** Determines whether the path refers to a directory. |
@param path path of the directory. | @param path path of the directory. |
|
|
*/ | */ |
static void translateSlashes(String& path); | static void translateSlashes(String& path); |
| |
|
/** Get an absolute path from an absolute directory and a relative or |
|
absolute file name. If the file name is fully specified, it is |
|
returned unchanged. Otherwise, the specified directory is prepended |
|
to the file name. |
|
*/ |
|
static String getAbsolutePath(const char* path, const String& filename); |
|
|
|
/** Return the just the filename to the file name into base. |
|
*/ |
|
static String extractFileName(const String& base); |
|
|
|
/** Return the just the path to the file name into path. |
|
*/ |
|
static String extractFilePath(const String& path); |
|
|
|
/** Changes file permissions on the given file. |
|
@param path path of the file. |
|
@param mode the bit-wise inclusive OR of the values for the |
|
desired permissions. |
|
@return true on success, false on error and errno is set appropriately. |
|
*/ |
|
static Boolean changeFilePermissions(const String& path, mode_t mode); |
|
|
|
/** |
|
Return OS path specific delimiter. |
|
|
|
@return delimiter specific to the platform |
|
*/ |
|
static String getPathDelimiter(); |
|
|
|
/** |
|
Returns the absolute pathname for the specified filename. |
|
|
|
@param paths directories seperated by an OS specific delimiter to search |
|
@param filename filename to search for in the paths |
|
|
|
@return the full absolute pathname to the found filename or an empty |
|
string on failure. |
|
*/ |
|
static String getAbsoluteFileName( |
|
const String& paths, |
|
const String& filename); |
|
|
|
/** |
|
Convert a library name to its corresponding file name by adding the |
|
appropriate prefix and suffix. |
|
|
|
@param libraryName The name of the library for which to build the file |
|
name. |
|
@return The file name corresponding to the specified library name. |
|
*/ |
|
static String buildLibraryFileName(const String &libraryName); |
|
|
|
/** |
|
Returns the platform-specific file name extension for dynamic |
|
libraries. |
|
|
|
@return the platform-specific file name extension for dynamic |
|
libraries. |
|
*/ |
|
static String getDynamicLibraryExtension(); |
|
|
|
static Boolean changeFileOwner( |
|
const String& fileName, |
|
const String& userName); |
|
|
|
/** |
|
Flushes the data from the iostream buffers to the OS buffers and |
|
then flushes the data from the OS buffers to the disk. |
|
|
|
This will avoid the possible data loss in case of an OS crash when |
|
OS filesystem commit directory-level changes immediately while |
|
file-level changes remain cached (e.g. HP-UX). |
|
|
|
@param fstream. The iostream that we want to flush data. |
|
*/ |
|
static void syncWithDirectoryUpdates(PEGASUS_STD(fstream)&); |
|
|
private: | private: |
| |
FileSystem() { } | FileSystem() { } |
|
|
return FileSystem::removeFile(realPath); | return FileSystem::removeFile(realPath); |
} | } |
| |
|
inline Boolean FileSystem::renameFileNoCase( |
|
const String& oldPath, |
|
const String& newPath) |
|
{ |
|
String realPath; |
|
|
|
if (!existsNoCase(oldPath, realPath)) |
|
return false; |
|
|
|
return FileSystem::renameFile(realPath, newPath); |
|
} |
|
|
inline Boolean FileSystem::getFileSizeNoCase(const String& path, Uint32& size) | inline Boolean FileSystem::getFileSizeNoCase(const String& path, Uint32& size) |
{ | { |
String realPath; | String realPath; |
|
|
return FileSystem::getFileSize(realPath, size); | return FileSystem::getFileSize(realPath, size); |
} | } |
| |
|
inline String FileSystem::getAbsolutePath( |
|
const char* path, |
|
const String& filename) |
|
{ |
|
String absolutePath; |
|
|
|
if (filename != String::EMPTY) |
|
{ |
|
if (!System::is_absolute_path(filename.getCString()) && path && path[0]) |
|
{ |
|
absolutePath.append(path); |
|
absolutePath.append('/'); |
|
} |
|
absolutePath.append(filename); |
|
} |
|
translateSlashes(absolutePath); |
|
|
|
return absolutePath; |
|
} |
|
|
|
inline Boolean Open(PEGASUS_STD(ifstream)& is, const String& path) |
|
{ |
|
is.open(path.getCString()); |
|
return !!is; |
|
} |
|
|
|
inline Boolean Open(PEGASUS_STD(ofstream)& os, const String& path) |
|
{ |
|
os.open(path.getCString()); |
|
return !!os; |
|
} |
|
|
|
inline Boolean OpenAppend(PEGASUS_STD(ofstream)& os, const String& path) |
|
{ |
|
os.open(path.getCString(), PEGASUS_STD(ios::app)); |
|
return !!os; |
|
} |
|
|
|
inline String FileSystem::getPathDelimiter() |
|
{ |
|
#if defined(PEGASUS_OS_TYPE_WINDOWS) |
|
return String(";"); |
|
#else |
|
return String(":"); |
|
#endif |
|
} |
|
|
|
/** Get the next line from the input file. |
|
*/ |
|
PEGASUS_COMMON_LINKAGE Boolean GetLine(PEGASUS_STD(istream)& is, String& line); |
|
|
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |
| |
#endif /* Pegasus_FileSystem_h */ | #endif /* Pegasus_FileSystem_h */ |