version 1.31.2.2, 2007/01/11 01:34:35
|
version 1.32, 2007/10/17 20:38:06
|
|
|
| |
#include <Pegasus/Common/FileSystem.h> | #include <Pegasus/Common/FileSystem.h> |
#include <Pegasus/Common/TraceFileHandler.h> | #include <Pegasus/Common/TraceFileHandler.h> |
#include <Pegasus/Common/Executor.h> |
|
| |
#if defined(PEGASUS_OS_TYPE_WINDOWS) | #if defined(PEGASUS_OS_TYPE_WINDOWS) |
# include <Pegasus/Common/TraceFileHandlerWindows.cpp> | # include <Pegasus/Common/TraceFileHandlerWindows.cpp> |
|
|
FILE* TraceFileHandler::_openFile(const char* fileName) | FILE* TraceFileHandler::_openFile(const char* fileName) |
{ | { |
#ifdef PEGASUS_OS_VMS | #ifdef PEGASUS_OS_VMS |
|
// FILE* fileHandle = fopen(fileName,"a+", "shr=get,put,upd"); |
FILE* fileHandle = fopen(fileName,"w", "shr=get,put,upd"); | FILE* fileHandle = fopen(fileName,"w", "shr=get,put,upd"); |
#else | #else |
FILE* fileHandle = Executor::openFile(fileName, 'a'); |
FILE* fileHandle = fopen(fileName,"a+"); |
#endif | #endif |
if (!fileHandle) | if (!fileHandle) |
{ | { |
|
|
return 0; | return 0; |
} | } |
| |
// We are done if the executor was used to perform this. Otherwise, we |
|
// must proceed to fix file ownership and permissions. |
|
|
|
if (Executor::detectExecutor() == 0) |
|
return fileHandle; |
|
|
|
// | // |
// Verify that the file has the correct owner | // Verify that the file has the correct owner |
// | // |
|
|
return fileHandle; | return fileHandle; |
} | } |
| |
static bool _canWrite(const String& path) |
|
{ |
|
if (Executor::detectExecutor() == 0) |
|
return true; |
|
else |
|
return FileSystem::canWrite(path); |
|
} |
|
|
|
Boolean TraceFileHandler::isValidFilePath(const char* filePath) | Boolean TraceFileHandler::isValidFilePath(const char* filePath) |
{ | { |
String fileName = String(filePath); | String fileName = String(filePath); |
|
|
FileSystem::translateSlashes(fileName); | FileSystem::translateSlashes(fileName); |
if (FileSystem::isDirectory(fileName)) | if (FileSystem::isDirectory(fileName)) |
{ | { |
return 0; |
return false; |
} | } |
| |
// Check if the file exists and is writable | // Check if the file exists and is writable |
if (FileSystem::exists(fileName)) | if (FileSystem::exists(fileName)) |
{ | { |
if (!_canWrite(fileName)) |
return FileSystem::canWrite(fileName); |
{ |
|
return 0; |
|
} |
|
else |
|
{ |
|
return 1; |
|
} | } |
} |
|
else |
|
{ |
|
// Check if directory is writable | // Check if directory is writable |
Uint32 index = fileName.reverseFind('/'); | Uint32 index = fileName.reverseFind('/'); |
| |
if (index != PEG_NOT_FOUND) | if (index != PEG_NOT_FOUND) |
{ | { |
String dirName = fileName.subString(0,index); | String dirName = fileName.subString(0,index); |
if (!FileSystem::isDirectory(dirName)) |
|
{ |
if (dirName.size() == 0) |
return 0; |
|
} |
|
if (!_canWrite(dirName) ) |
|
{ | { |
return 0; |
dirName = "/"; |
} | } |
else |
|
|
if (!FileSystem::isDirectory(dirName)) |
{ | { |
return 1; |
return false; |
} | } |
|
|
|
return FileSystem::canWrite(dirName); |
} | } |
else |
|
{ |
|
String currentDir; | String currentDir; |
| |
// Check if there is permission to write in the | // Check if there is permission to write in the |
// current working directory | // current working directory |
FileSystem::getCurrentDirectory(currentDir); | FileSystem::getCurrentDirectory(currentDir); |
| |
if (!_canWrite(currentDir)) |
return FileSystem::canWrite(currentDir); |
{ |
|
return 0; |
|
} |
|
else |
|
{ |
|
return 1; |
|
} | } |
} |
|
} |
|
PEGASUS_UNREACHABLE(return 1;) |
|
} |
|
|
|
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |