Page Speed Optimization Libraries
1.13.35.1
|
#include "mem_file_system.h"
Public Types | |
typedef Callback1< const GoogleString & > | FileCallback |
Public Member Functions | |
MemFileSystem (ThreadSystem *threads, Timer *timer) | |
virtual InputFile * | OpenInputFile (const char *filename, MessageHandler *message_handler) |
virtual OutputFile * | OpenOutputFileHelper (const char *filename, bool append, MessageHandler *message_handler) |
virtual OutputFile * | OpenTempFileHelper (const StringPiece &prefix_name, MessageHandler *message_handle) |
virtual bool | ListContents (const StringPiece &dir, StringVector *files, MessageHandler *handler) |
virtual bool | MakeDir (const char *directory_path, MessageHandler *handler) |
virtual bool | RecursivelyMakeDir (const StringPiece &directory_path, MessageHandler *handler) |
virtual bool | RemoveDir (const char *path, MessageHandler *handler) |
Like POSIX 'rmdir', remove a directory only if it is empty. | |
virtual bool | RemoveFile (const char *filename, MessageHandler *handler) |
Like POSIX 'rm'. | |
virtual bool | RenameFileHelper (const char *old_file, const char *new_file, MessageHandler *handler) |
virtual bool | Atime (const StringPiece &path, int64 *timestamp_sec, MessageHandler *handler) |
virtual bool | Mtime (const StringPiece &path, int64 *timestamp_sec, MessageHandler *handler) |
Modified time. Time the file contents were modified. | |
virtual bool | Size (const StringPiece &path, int64 *size, MessageHandler *handler) const |
virtual BoolOrError | Exists (const char *path, MessageHandler *handler) |
Like POSIX 'test -e', checks if path exists (is a file, directory, etc.). | |
virtual BoolOrError | IsDir (const char *path, MessageHandler *handler) |
Like POSIX 'test -d', checks if path exists and refers to a directory. | |
virtual BoolOrError | TryLock (const StringPiece &lock_name, MessageHandler *handler) |
virtual BoolOrError | TryLockWithTimeout (const StringPiece &lock_name, int64 timeout_ms, const Timer *timer, MessageHandler *handler) |
virtual bool | BumpLockTimeout (const StringPiece &lock_name, MessageHandler *handler) |
virtual bool | Unlock (const StringPiece &lock_name, MessageHandler *handler) |
void | set_atime_enabled (bool enabled) |
When atime is disabled, reading a file will not update its atime. | |
bool | advance_time_on_update () |
void | set_advance_time_on_update (bool x, MockTimer *mock_timer) |
void | Clear () |
void | Disable () |
Test-specific functionality to disable and re-enable the filesystem. | |
void | Enable () |
void | ClearStats () |
Access statistics. | |
int | num_input_file_opens () const |
int | num_input_file_stats () const |
returns number of times MTime was called. | |
int | num_output_file_opens () const |
int | num_temp_file_opens () const |
void | set_write_callback (FileCallback *x) |
virtual bool | WriteFile (const char *filename, const StringPiece &buffer, MessageHandler *handler) |
Non-atomic. Use WriteFileAtomic() for atomic version. | |
virtual bool | WriteTempFile (const StringPiece &prefix_name, const StringPiece &buffer, GoogleString *filename, MessageHandler *handler) |
Public Member Functions inherited from net_instaweb::FileSystem | |
virtual int | MaxPathLength (const StringPiece &base) const |
virtual bool | ReadFile (const char *filename, int64 max_file_size, Writer *writer, MessageHandler *handler) |
virtual bool | ReadFile (InputFile *input_file, int64 max_file_size, Writer *writer, MessageHandler *handler) |
virtual bool | ReadFile (const char *filename, int64 max_file_size, GoogleString *buffer, MessageHandler *handler) |
virtual bool | ReadFile (InputFile *input_file, int64 max_file_size, GoogleString *buffer, MessageHandler *handler) |
virtual bool | ReadFile (const char *filename, GoogleString *buffer, MessageHandler *handler) |
virtual bool | ReadFile (InputFile *input_file, GoogleString *buffer, MessageHandler *handler) |
virtual bool | ReadFile (const char *filename, Writer *writer, MessageHandler *handler) |
virtual bool | ReadFile (InputFile *input_file, Writer *writer, MessageHandler *handler) |
bool | WriteFileAtomic (const StringPiece &filename, const StringPiece &buffer, MessageHandler *handler) |
OutputFile * | OpenOutputFile (const char *filename, MessageHandler *handler) |
Automatically creates sub-directories to filename. | |
OutputFile * | OpenOutputFileForAppend (const char *filename, MessageHandler *handler) |
OutputFile * | OpenTempFile (const StringPiece &prefix_name, MessageHandler *handler) |
virtual bool | Close (File *file, MessageHandler *handler) |
Closes the File and cleans up memory. | |
bool | RenameFile (const char *old_filename, const char *new_filename, MessageHandler *handler) |
void | GetDirInfo (const StringPiece &path, DirInfo *dirinfo, MessageHandler *handler) |
virtual void | GetDirInfoWithProgress (const StringPiece &path, DirInfo *dirinfo, ProgressNotifier *notifier, MessageHandler *handler) |
Additional Inherited Members | |
Static Public Attributes inherited from net_instaweb::FileSystem | |
static const int64 | kUnlimitedSize = -1 |
This is documented as -1 in user-facing documentation, so don't change it. | |
An in-memory implementation of the FileSystem interface. This was originally for use in unit tests; but can also host the lock manager if needed. Does not fully support directories. Not particularly efficient. Not threadsafe except for lock methods.
|
inline |
In order to test file-system 'atime' code, we need to move mock time forward during tests by an entire second (aka 1000 ms). However, that's disruptive to other tests that try to use mock-time to examine millisecond-level timing, so we leave this behavior off by default.
|
virtual |
We offer a "simulated atime" in which the clock ticks forward one second every time you read or write a file.
Implements net_instaweb::FileSystem.
|
virtual |
If you're holding a lock for a long running task you want to avoid someone else receiving the lock if they request it with TryLockWithTimeout because you've been working for longer than the timeout, you should bump it often enough that it doesn't expire.
Default implementation does nothing, since the default implementation of TryLockWithTimeout doesn't do anything either.
Reimplemented from net_instaweb::FileSystem.
void net_instaweb::MemFileSystem::Clear | ( | ) |
Empties out the entire filesystem. Should not be called while files are open.
|
virtual |
Like POSIX 'ls -a', lists all files and directories under the given directory (but omits "." and ".."). Full paths (not just filenames) will be pushed onto the back of the supplied vector (without clearing it). Returns true on success (even if the dir was empty), false on error (even if some files were pushed onto the vector). This is generally not threadsafe! Use a mutex.
Implements net_instaweb::FileSystem.
|
virtual |
Like POSIX 'mkdir', makes a directory only if parent directory exists. Fails if directory_name already exists or parent directory doesn't exist.
Implements net_instaweb::FileSystem.
|
virtual |
These interfaces must be defined by implementers of FileSystem. They may assume the directory already exists.
Implements net_instaweb::FileSystem.
|
virtual |
Like POSIX 'mkdir -p', makes all directories up to this one recursively. Fails if we do not have permission to make any directory in chain.
Reimplemented from net_instaweb::FileSystem.
|
inline |
Adds a callback to be called once after a file-write and then deleted.
This is intended primarily for testing, and thus is not on the base class.
|
virtual |
Given a file, computes its size in bytes and store it in *size. Returns true on success, false on failure. Behavior is undefined if path refers to a directory. This function has different behavior depending on the underlying implementation. Memory-based implementations will report the size of the file, while disk-based implementations should return the actual allocated size on disk.
Implements net_instaweb::FileSystem.
|
virtual |
Attempts to obtain a global (cross-process, cross-thread) lock of the given name (which should be a valid filename, not otherwise used, in an extant directory). If someone else has this lock, returns False immediately. If anything goes wrong, returns Error. On success, returns True: then you must call Unlock when you are done.
Implements net_instaweb::FileSystem.
|
virtual |
Like TryLock, but may attempt to break stale locks, though the default implementation never actually breaks any. A lock is stale if it was taken (or last bumped) more than timeout_millis ms ago.
If you obtain a lock through this method, there are no hard guarantees that nobody else has it too. <blink> If you use this function, your lock becomes "best-effort". </blink>
If you override this function, you need to override BumpLockTimeout as well.
Reimplemented from net_instaweb::FileSystem.
|
virtual |
Attempts to release a lock previously obtained through TryLock. If your thread did not previously obtain the lock, the behavior is undefined. Returns true if we successfully release the lock. Returns false if we were unable to release the lock (e.g. somebody came along and write-protected the lockfile). You might try again, or start using a different lock name.
Implements net_instaweb::FileSystem.
|
virtual |
Writes given data to a temp file in one shot, storing the filename in filename on success. Returns false and clears filename on failure.
Reimplemented from net_instaweb::FileSystem.