00001
00016
00017 #ifndef NET_INSTAWEB_APACHE_APR_FILE_SYSTEM_H_
00018 #define NET_INSTAWEB_APACHE_APR_FILE_SYSTEM_H_
00019
00020 #include "apr.h"
00021 #include "base/scoped_ptr.h"
00022 #include "net/instaweb/util/public/basictypes.h"
00023 #include "net/instaweb/util/public/file_system.h"
00024 #include "net/instaweb/util/public/message_handler.h"
00025
00026 struct apr_finfo_t;
00027 struct apr_pool_t;
00028
00029 namespace net_instaweb {
00030
00031 class AbstractMutex;
00032 class ThreadSystem;
00033
00034 void AprReportError(MessageHandler* message_handler, const char* filename,
00035 int line, const char* message, int error_code);
00036
00037 class AprFileSystem : public FileSystem {
00038 public:
00039 AprFileSystem(apr_pool_t* pool, ThreadSystem* thread_system);
00040 ~AprFileSystem();
00041
00042 virtual int MaxPathLength(const StringPiece& base) const;
00043 virtual InputFile* OpenInputFile(
00044 const char* file, MessageHandler* message_handler);
00045 virtual OutputFile* OpenOutputFileHelper(
00046 const char* file, MessageHandler* message_handler);
00048 virtual OutputFile* OpenTempFileHelper(const StringPiece& prefix_name,
00049 MessageHandler* message_handler);
00050
00051 virtual bool ListContents(const StringPiece& dir, StringVector* files,
00052 MessageHandler* handler);
00055 virtual bool MakeDir(const char* directory_path, MessageHandler* handler);
00056 virtual bool RemoveFile(const char* filename,
00057 MessageHandler* message_handler);
00058 virtual bool RenameFileHelper(const char* old_filename,
00059 const char* new_filename,
00060 MessageHandler* message_handler);
00061
00062 virtual bool Atime(const StringPiece& path,
00063 int64* timestamp_sec, MessageHandler* handler);
00064 virtual bool Mtime(const StringPiece& path,
00065 int64* timestamp_sec, MessageHandler* handler);
00066 virtual bool Size(const StringPiece& path, int64* size,
00067 MessageHandler* handler);
00068 virtual BoolOrError Exists(const char* path, MessageHandler* handler);
00069 virtual BoolOrError IsDir(const char* path, MessageHandler* handler);
00070
00071 virtual BoolOrError TryLock(const StringPiece& lock_name,
00072 MessageHandler* handler);
00073 virtual BoolOrError TryLockWithTimeout(const StringPiece& lock_name,
00074 int64 timeout_ms,
00075 MessageHandler* handler);
00076 virtual bool Unlock(const StringPiece& lock_name, MessageHandler* handler);
00077
00078 private:
00080 bool Stat(const StringPiece& path,
00081 apr_finfo_t* file_info, apr_int32_t field_wanted,
00082 MessageHandler* handler);
00083
00084 apr_pool_t* pool_;
00085
00089 scoped_ptr<AbstractMutex> mutex_;
00090
00091 DISALLOW_COPY_AND_ASSIGN(AprFileSystem);
00092 };
00093
00094 }
00095
00096 #endif ///< NET_INSTAWEB_APACHE_APR_FILE_SYSTEM_H_