19 #ifndef PAGESPEED_KERNEL_BASE_MEM_FILE_SYSTEM_H_
20 #define PAGESPEED_KERNEL_BASE_MEM_FILE_SYSTEM_H_
31 #include "pagespeed/kernel/base/thread_annotations.h"
33 namespace net_instaweb {
55 virtual InputFile* OpenInputFile(
const char* filename,
60 virtual OutputFile* OpenTempFileHelper(
const StringPiece& prefix_name,
63 virtual bool ListContents(
const StringPiece& dir, StringVector* files,
70 virtual bool RenameFileHelper(
const char* old_file,
const char* new_file,
75 virtual bool Atime(
const StringPiece& path, int64* timestamp_sec,
77 virtual bool Mtime(
const StringPiece& path, int64* timestamp_sec,
79 virtual bool Size(
const StringPiece& path, int64* size,
97 atime_enabled_ = enabled;
107 return advance_time_on_update_;
109 void set_advance_time_on_update(
bool x,
MockTimer* mock_timer) {
111 advance_time_on_update_ = x;
112 mock_timer_ = mock_timer;
132 num_input_file_opens_ = 0;
133 num_input_file_stats_ = 0;
134 num_output_file_opens_ = 0;
135 num_temp_file_opens_ = 0;
137 int num_input_file_opens()
const {
139 return num_input_file_opens_;
145 return num_input_file_stats_;
147 int num_output_file_opens()
const {
149 return num_output_file_opens_;
151 int num_temp_file_opens()
const {
153 return num_temp_file_opens_;
163 virtual bool WriteFile(
const char* filename,
164 const StringPiece& buffer,
167 const StringPiece& buffer,
173 inline void UpdateAtime(
const StringPiece& path)
174 SHARED_LOCKS_REQUIRED(all_else_mutex_);
175 inline void UpdateMtime(
const StringPiece& path)
176 SHARED_LOCKS_REQUIRED(all_else_mutex_);
182 bool enabled_ GUARDED_BY(all_else_mutex_);
186 StringStringMap string_map_ GUARDED_BY(all_else_mutex_);
189 MockTimer* mock_timer_ GUARDED_BY(all_else_mutex_);
195 std::map<GoogleString, int64> atime_map_ GUARDED_BY(all_else_mutex_);
196 std::map<GoogleString, int64> mtime_map_ GUARDED_BY(all_else_mutex_);
197 int temp_file_index_ GUARDED_BY(all_else_mutex_);
200 std::map<GoogleString, int64> lock_map_ GUARDED_BY(lock_map_mutex_);
201 bool atime_enabled_ GUARDED_BY(all_else_mutex_);
205 bool advance_time_on_update_ GUARDED_BY(all_else_mutex_);
208 int num_input_file_opens_ GUARDED_BY(all_else_mutex_);
209 int num_input_file_stats_ GUARDED_BY(all_else_mutex_);
210 int num_output_file_opens_ GUARDED_BY(all_else_mutex_);
211 int num_temp_file_opens_ GUARDED_BY(all_else_mutex_);
Definition: mock_timer.h:33
virtual bool RecursivelyMakeDir(const StringPiece &directory_path, MessageHandler *handler)
void Disable()
Test-specific functionality to disable and re-enable the filesystem.
Definition: mem_file_system.h:120
Definition: file_system.h:35
virtual bool Size(const StringPiece &path, int64 *size, MessageHandler *handler) const
virtual bool WriteFile(const char *filename, const StringPiece &buffer, MessageHandler *handler)
Non-atomic. Use WriteFileAtomic() for atomic version.
Definition: scoped_ptr.h:30
virtual BoolOrError TryLock(const StringPiece &lock_name, MessageHandler *handler)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
#define ScopedMutex(x)
Definition: abstract_mutex.h:69
Helper class for lexically scoped mutexing.
Definition: abstract_mutex.h:46
virtual bool RemoveFile(const char *filename, MessageHandler *handler)
Like POSIX 'rm'.
int num_input_file_stats() const
returns number of times MTime was called.
Definition: mem_file_system.h:143
Definition: file_system.h:76
virtual bool WriteTempFile(const StringPiece &prefix_name, const StringPiece &buffer, GoogleString *filename, MessageHandler *handler)
virtual bool Unlock(const StringPiece &lock_name, MessageHandler *handler)
virtual BoolOrError TryLockWithTimeout(const StringPiece &lock_name, int64 timeout_ms, const Timer *timer, MessageHandler *handler)
void set_write_callback(FileCallback *x)
Definition: mem_file_system.h:161
virtual bool RemoveDir(const char *path, MessageHandler *handler)
Like POSIX 'rmdir', remove a directory only if it is empty.
virtual bool MakeDir(const char *directory_path, MessageHandler *handler)
virtual bool ListContents(const StringPiece &dir, StringVector *files, MessageHandler *handler)
void ClearStats()
Access statistics.
Definition: mem_file_system.h:130
virtual bool Mtime(const StringPiece &path, int64 *timestamp_sec, MessageHandler *handler)
Modified time. Time the file contents were modified.
virtual bool Atime(const StringPiece &path, int64 *timestamp_sec, MessageHandler *handler)
Definition: thread_system.h:40
Definition: message_handler.h:39
Definition: mem_file_system.h:48
virtual bool BumpLockTimeout(const StringPiece &lock_name, MessageHandler *handler)
virtual OutputFile * OpenOutputFileHelper(const char *filename, bool append, MessageHandler *message_handler)
virtual BoolOrError IsDir(const char *path, MessageHandler *handler)
Like POSIX 'test -d', checks if path exists and refers to a directory.
bool advance_time_on_update()
Definition: mem_file_system.h:105
virtual BoolOrError Exists(const char *path, MessageHandler *handler)
Like POSIX 'test -e', checks if path exists (is a file, directory, etc.).
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
Definition: callback.h:44
void set_atime_enabled(bool enabled)
When atime is disabled, reading a file will not update its atime.
Definition: mem_file_system.h:95
Definition: file_system.h:113