2013-03-30 13:37:14 +00:00
|
|
|
#ifndef S3FS_S3FS_UTIL_H_
|
|
|
|
#define S3FS_S3FS_UTIL_H_
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// Typedef
|
|
|
|
//-------------------------------------------------------------------
|
2013-04-20 19:17:28 +00:00
|
|
|
//
|
|
|
|
// Struct
|
|
|
|
//
|
|
|
|
struct s3obj_entry{
|
|
|
|
std::string normalname; // normalized name: if empty, object is nomalized name.
|
|
|
|
std::string orgname; // original name: if empty, object is original name.
|
|
|
|
std::string etag;
|
|
|
|
bool is_dir;
|
|
|
|
|
|
|
|
s3obj_entry() : is_dir(false) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::map<std::string, struct s3obj_entry> s3obj_t;
|
|
|
|
typedef std::list<std::string> s3obj_list_t;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Class
|
|
|
|
//
|
|
|
|
class S3ObjList
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
s3obj_t objects;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool insert_nomalized(const char* name, const char* normalized, bool is_dir);
|
|
|
|
const s3obj_entry* GetS3Obj(const char* name) const;
|
|
|
|
|
|
|
|
s3obj_t::const_iterator begin(void) const {
|
|
|
|
return objects.begin();
|
|
|
|
}
|
|
|
|
s3obj_t::const_iterator end(void) const {
|
|
|
|
return objects.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
S3ObjList() {}
|
|
|
|
~S3ObjList() {}
|
|
|
|
|
|
|
|
bool IsEmpty(void) const {
|
|
|
|
return objects.empty();
|
|
|
|
}
|
|
|
|
bool insert(const char* name, const char* etag = NULL, bool is_dir = false);
|
|
|
|
std::string GetOrgName(const char* name) const;
|
|
|
|
std::string GetNormalizedName(const char* name) const;
|
|
|
|
std::string GetETag(const char* name) const;
|
|
|
|
bool IsDir(const char* name) const;
|
|
|
|
bool GetNameList(s3obj_list_t& list, bool OnlyNormalized = true, bool CutSlash = true) const;
|
2013-04-29 14:31:10 +00:00
|
|
|
|
|
|
|
static bool MakeHierarchizedList(s3obj_list_t& list, bool haveSlash);
|
2013-03-30 13:37:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct mvnode {
|
|
|
|
char *old_path;
|
|
|
|
char *new_path;
|
|
|
|
bool is_dir;
|
2013-04-29 14:31:10 +00:00
|
|
|
bool is_normdir;
|
2013-03-30 13:37:14 +00:00
|
|
|
struct mvnode *prev;
|
|
|
|
struct mvnode *next;
|
|
|
|
} MVNODE;
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// Functions
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
std::string get_realpath(const char *path);
|
|
|
|
|
2013-04-29 14:31:10 +00:00
|
|
|
MVNODE *create_mvnode(const char *old_path, const char *new_path, bool is_dir, bool normdir = false);
|
|
|
|
MVNODE *add_mvnode(MVNODE** head, MVNODE** tail, const char *old_path, const char *new_path, bool is_dir, bool normdir = false);
|
2013-03-30 13:37:14 +00:00
|
|
|
void free_mvnodes(MVNODE *head);
|
|
|
|
|
|
|
|
std::string get_username(uid_t uid);
|
|
|
|
int is_uid_inculde_group(uid_t uid, gid_t gid);
|
|
|
|
|
|
|
|
std::string mydirname(std::string path);
|
|
|
|
std::string mybasename(std::string path);
|
|
|
|
int mkdirp(const std::string& path, mode_t mode);
|
|
|
|
|
|
|
|
time_t get_mtime(const char *s);
|
2013-05-09 08:35:17 +00:00
|
|
|
time_t get_mtime(headers_t& meta, bool overcheck = true);
|
2013-03-30 13:37:14 +00:00
|
|
|
off_t get_size(const char *s);
|
2013-05-09 08:35:17 +00:00
|
|
|
off_t get_size(headers_t& meta);
|
2013-03-30 13:37:14 +00:00
|
|
|
mode_t get_mode(const char *s);
|
2013-05-09 08:35:17 +00:00
|
|
|
mode_t get_mode(headers_t& meta, const char* path = NULL, bool checkdir = false, bool forcedir = false);
|
2013-03-30 13:37:14 +00:00
|
|
|
uid_t get_uid(const char *s);
|
2013-05-09 08:35:17 +00:00
|
|
|
uid_t get_uid(headers_t& meta);
|
2013-03-30 13:37:14 +00:00
|
|
|
gid_t get_gid(const char *s);
|
2013-05-09 08:35:17 +00:00
|
|
|
gid_t get_gid(headers_t& meta);
|
2013-03-30 13:37:14 +00:00
|
|
|
blkcnt_t get_blocks(off_t size);
|
2013-04-06 17:39:22 +00:00
|
|
|
time_t get_lastmodified(const char* s);
|
2013-05-09 08:35:17 +00:00
|
|
|
time_t get_lastmodified(headers_t& meta);
|
2013-06-19 14:53:58 +00:00
|
|
|
bool is_need_check_obj_detail(headers_t& meta);
|
2013-03-30 13:37:14 +00:00
|
|
|
|
|
|
|
void show_usage(void);
|
|
|
|
void show_help(void);
|
|
|
|
void show_version(void);
|
|
|
|
|
|
|
|
#endif // S3FS_S3FS_UTIL_H_
|