00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <sys/types.h>
00024 #include <sys/stat.h>
00025 #if defined(__digital__)
00026 #include <sys/mode.h>
00027 #endif
00028 #include <Basics.H>
00029 #include <FS.H>
00030 #include "StatDirEntry.H"
00031 #include "StatMPKFile.H"
00032 #include "StatDir.H"
00033
00034 int DirEntry::Search(int verbose, Stat::Collection &stats)
00035 throw (StatError::UnevenLevels, StatError::BadMPKFile, StatError::EndOfFile,
00036 FS::Failure, FS::DoesNotExist)
00037 {
00038 assert(false);
00039 return 0;
00040 }
00041
00042 void DirEntry::FSStat(const Text &path, struct stat *buffer)
00043 throw (FS::Failure, FS::DoesNotExist)
00044 {
00045 if (stat(path.cchars(), buffer) != 0) {
00046 if (errno == ENOENT) throw FS::DoesNotExist();
00047 else throw FS::Failure(Text("stat"), path);
00048 }
00049 }
00050
00051 DirEntry *DirEntry::Open(const Text &path, struct stat *statBuff)
00052 throw (StatError::EndOfFile, FS::Failure, FS::DoesNotExist)
00053 {
00054 DirEntry *res;
00055 struct stat buffer;
00056 if (statBuff == (struct stat *)NULL) {
00057 statBuff = &buffer;
00058 FSStat(path, statBuff);
00059 }
00060 if (S_ISDIR(statBuff->st_mode)) {
00061 res = NEW_CONSTR(DirObj, (path));
00062 } else {
00063 assert(S_ISREG(statBuff->st_mode));
00064 res = NEW_CONSTR(MPKFileObj, (path));
00065 }
00066 return res;
00067 }