19 #ifndef PAGESPEED_KERNEL_BASE_FILE_SYSTEM_H_
20 #define PAGESPEED_KERNEL_BASE_FILE_SYSTEM_H_
28 namespace net_instaweb {
44 explicit BoolOrError(
bool t_or_f) : choice_(t_or_f ? kIsTrue : kIsFalse) { }
50 choice_ = src.choice_;
55 bool is_false()
const {
return choice_ == kIsFalse; }
56 bool is_true()
const {
return choice_ == kIsTrue; }
57 bool is_error()
const {
return choice_ == kIsError; }
58 void set_error() { choice_ = kIsError; }
59 void set(
bool t_or_f) { choice_ = t_or_f ? kIsTrue : kIsFalse; }
128 virtual void Notify() = 0;
134 void Notify()
override {}
139 : size_bytes(size_bytes), atime_sec(atime_sec), name(name) {}
147 DirInfo() : size_bytes(0), inode_count(0) { }
149 std::vector<FileInfo> files;
150 StringVector empty_dirs;
166 virtual bool ReadFile(
const char* filename,
174 virtual bool ReadFile(
const char* filename,
187 virtual bool ReadFile(
const char* filename,
193 virtual bool ReadFile(
const char* filename,
200 virtual bool WriteFile(
const char* filename,
201 const StringPiece& buffer,
206 const StringPiece& buffer,
214 const StringPiece& buffer,
217 virtual InputFile* OpenInputFile(
const char* filename,
222 SetupFileDir(filename, handler);
229 SetupFileDir(filename, handler);
239 SetupFileDir(prefix_name, handler);
240 return OpenTempFileHelper(prefix_name, handler);
252 bool RenameFile(
const char* old_filename,
const char* new_filename,
254 SetupFileDir(new_filename, handler);
255 return RenameFileHelper(old_filename, new_filename, handler);
263 virtual bool RemoveDir(
const char* directory_path,
283 virtual bool ListContents(
const StringPiece& dir, StringVector* files,
291 virtual bool Atime(
const StringPiece& path, int64* timestamp_sec,
295 virtual bool Mtime(
const StringPiece& path, int64* timestamp_sec,
306 void GetDirInfo(
const StringPiece& path, DirInfo* dirinfo,
312 const StringPiece& path, DirInfo* dirinfo,
323 virtual bool Size(
const StringPiece& path, int64* size,
345 int64 timeout_millis,
348 return TryLock(lock_name, handler);
367 virtual bool Unlock(
const StringPiece& lock_name,
376 virtual OutputFile* OpenTempFileHelper(
const StringPiece& filename,
378 virtual bool RenameFileHelper(
const char* old_filename,
379 const char* new_filename,
384 void SetupFileDir(
const StringPiece& filename,
MessageHandler* handler);
virtual BoolOrError IsDir(const char *path, MessageHandler *handler)=0
Like POSIX 'test -d', checks if path exists and refers to a directory.
void GetDirInfo(const StringPiece &path, DirInfo *dirinfo, MessageHandler *handler)
Definition: file_system.h:126
virtual bool Atime(const StringPiece &path, int64 *timestamp_sec, MessageHandler *handler)=0
virtual bool RecursivelyMakeDir(const StringPiece &directory_path, MessageHandler *handler)
virtual bool MakeDir(const char *directory_path, MessageHandler *handler)=0
virtual bool BumpLockTimeout(const StringPiece &lock_name, MessageHandler *handler)
Definition: file_system.h:355
virtual int MaxPathLength(const StringPiece &base) const
Definition: file_system.h:35
virtual bool RemoveDir(const char *directory_path, MessageHandler *handler)=0
Like POSIX 'rmdir', remove a directory only if it is empty.
virtual bool Write(const StringPiece &buf, MessageHandler *handler)=0
Definition: file_system.h:132
OutputFile * OpenTempFile(const StringPiece &prefix_name, MessageHandler *handler)
Definition: file_system.h:237
virtual bool Mtime(const StringPiece &path, int64 *timestamp_sec, MessageHandler *handler)=0
Modified time. Time the file contents were modified.
virtual bool WriteFile(const char *filename, const StringPiece &buffer, MessageHandler *handler)
Non-atomic. Use WriteFileAtomic() for atomic version.
virtual BoolOrError TryLock(const StringPiece &lock_name, MessageHandler *handler)=0
virtual bool Close(File *file, MessageHandler *handler)
Closes the File and cleans up memory.
virtual void GetDirInfoWithProgress(const StringPiece &path, DirInfo *dirinfo, ProgressNotifier *notifier, MessageHandler *handler)
OutputFile * OpenOutputFile(const char *filename, MessageHandler *handler)
Automatically creates sub-directories to filename.
Definition: file_system.h:220
static const int64 kUnlimitedSize
This is documented as -1 in user-facing documentation, so don't change it.
Definition: file_system.h:79
virtual const char * filename()=0
Gets the name of the file.
virtual BoolOrError TryLockWithTimeout(const StringPiece &lock_name, int64 timeout_millis, const Timer *timer, MessageHandler *handler)
Definition: file_system.h:344
bool RenameFile(const char *old_filename, const char *new_filename, MessageHandler *handler)
Definition: file_system.h:252
virtual bool Unlock(const StringPiece &lock_name, MessageHandler *handler)=0
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
OutputFile * OpenOutputFileForAppend(const char *filename, MessageHandler *handler)
Definition: file_system.h:227
virtual OutputFile * OpenOutputFileHelper(const char *filename, bool append, MessageHandler *handler)=0
Definition: file_system.h:146
BoolOrError(const BoolOrError &src)
Intended to be passed by value; explicitly support copy & assign.
Definition: file_system.h:47
Definition: file_system.h:76
Interface for writing bytes to an output stream.
Definition: writer.h:29
bool WriteFileAtomic(const StringPiece &filename, const StringPiece &buffer, MessageHandler *handler)
Definition: file_system.h:137
virtual bool ReadFile(const char *filename, int64 max_file_size, Writer *writer, MessageHandler *handler)
virtual bool WriteTempFile(const StringPiece &prefix_name, const StringPiece &buffer, GoogleString *filename, MessageHandler *handler)
virtual bool Size(const StringPiece &path, int64 *size, MessageHandler *handler) const =0
Definition: message_handler.h:39
virtual bool RemoveFile(const char *filename, MessageHandler *handler)=0
Like POSIX 'rm'.
virtual BoolOrError Exists(const char *path, MessageHandler *handler)=0
Like POSIX 'test -e', checks if path exists (is a file, directory, etc.).
Definition: file_system.h:83
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
virtual bool ListContents(const StringPiece &dir, StringVector *files, MessageHandler *handler)=0
Definition: file_system.h:113