mirror of
https://github.com/TurboGit/hubicfuse.git
synced 2026-08-01 18:32:23 +02:00
Reformat code using astyle.
This commit is contained in:
+449
-368
File diff suppressed because it is too large
Load Diff
+27
-23
@@ -16,12 +16,14 @@
|
||||
typedef struct curl_slist curl_slist;
|
||||
|
||||
#define MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL 5
|
||||
struct curl_progress {
|
||||
struct curl_progress
|
||||
{
|
||||
double lastruntime;
|
||||
CURL *curl;
|
||||
CURL* curl;
|
||||
};
|
||||
|
||||
typedef struct options {
|
||||
typedef struct options
|
||||
{
|
||||
char cache_timeout[OPTION_SIZE];
|
||||
char verify_ssl[OPTION_SIZE];
|
||||
char segment_size[OPTION_SIZE];
|
||||
@@ -34,7 +36,8 @@ typedef struct options {
|
||||
char refresh_token[OPTION_SIZE];
|
||||
} FuseOptions;
|
||||
|
||||
typedef struct extra_options {
|
||||
typedef struct extra_options
|
||||
{
|
||||
char get_extended_metadata[OPTION_SIZE];
|
||||
char curl_verbose[OPTION_SIZE];
|
||||
char cache_statfs_timeout[OPTION_SIZE];
|
||||
@@ -46,40 +49,41 @@ typedef struct extra_options {
|
||||
|
||||
void cloudfs_init(void);
|
||||
void cloudfs_free(void);
|
||||
void cloudfs_set_credentials(char *client_id, char *client_secret, char *refresh_token);
|
||||
void cloudfs_set_credentials(char* client_id, char* client_secret,
|
||||
char* refresh_token);
|
||||
int cloudfs_connect(void);
|
||||
|
||||
struct segment_info
|
||||
{
|
||||
FILE *fp;
|
||||
FILE* fp;
|
||||
int part;
|
||||
long size;
|
||||
long segment_size;
|
||||
char *seg_base;
|
||||
const char *method;
|
||||
char* seg_base;
|
||||
const char* method;
|
||||
};
|
||||
|
||||
long segment_size;
|
||||
long segment_above;
|
||||
|
||||
char *override_storage_url;
|
||||
char *public_container;
|
||||
char* override_storage_url;
|
||||
char* public_container;
|
||||
|
||||
int file_is_readable(const char *fname);
|
||||
const char * get_file_mimetype ( const char *filename );
|
||||
int cloudfs_object_read_fp(const char *path, FILE *fp);
|
||||
int cloudfs_object_write_fp(const char *path, FILE *fp);
|
||||
int cloudfs_list_directory(const char *path, dir_entry **);
|
||||
int cloudfs_delete_object(const char *path);
|
||||
int cloudfs_copy_object(const char *src, const char *dst);
|
||||
int cloudfs_create_symlink(const char *src, const char *dst);
|
||||
int cloudfs_create_directory(const char *label);
|
||||
int cloudfs_object_truncate(const char *path, off_t size);
|
||||
int file_is_readable(const char* fname);
|
||||
const char* get_file_mimetype ( const char* filename );
|
||||
int cloudfs_object_read_fp(const char* path, FILE* fp);
|
||||
int cloudfs_object_write_fp(const char* path, FILE* fp);
|
||||
int cloudfs_list_directory(const char* path, dir_entry**);
|
||||
int cloudfs_delete_object(const char* path);
|
||||
int cloudfs_copy_object(const char* src, const char* dst);
|
||||
int cloudfs_create_symlink(const char* src, const char* dst);
|
||||
int cloudfs_create_directory(const char* label);
|
||||
int cloudfs_object_truncate(const char* path, off_t size);
|
||||
off_t cloudfs_file_size(int fd);
|
||||
int cloudfs_statfs(const char *path, struct statvfs *stat);
|
||||
int cloudfs_statfs(const char* path, struct statvfs* stat);
|
||||
void cloudfs_verify_ssl(int dbg);
|
||||
void cloudfs_option_get_extended_metadata(int option);
|
||||
void cloudfs_option_curl_verbose(int option);
|
||||
void get_file_metadata(dir_entry *de);
|
||||
int cloudfs_update_meta(dir_entry *de);
|
||||
void get_file_metadata(dir_entry* de);
|
||||
int cloudfs_update_meta(dir_entry* de);
|
||||
#endif
|
||||
|
||||
+342
-251
File diff suppressed because it is too large
Load Diff
+138
-122
@@ -26,8 +26,8 @@
|
||||
|
||||
pthread_mutex_t dcachemut;
|
||||
pthread_mutexattr_t mutex_attr;
|
||||
dir_cache *dcache;
|
||||
char *temp_dir;
|
||||
dir_cache* dcache;
|
||||
char* temp_dir;
|
||||
int cache_timeout;
|
||||
int debug = 0;
|
||||
int verify_ssl = 2;
|
||||
@@ -45,7 +45,7 @@ size_t file_buffer_size = 0;
|
||||
// needed to get correct GMT / local time
|
||||
// hubic stores time as GMT so we have to do conversions
|
||||
// http://zhu-qy.blogspot.ro/2012/11/ref-how-to-convert-from-utc-to-local.html
|
||||
time_t my_timegm(struct tm *tm)
|
||||
time_t my_timegm(struct tm* tm)
|
||||
{
|
||||
time_t epoch = 0;
|
||||
time_t offset = mktime(gmtime(&epoch));
|
||||
@@ -54,7 +54,7 @@ time_t my_timegm(struct tm *tm)
|
||||
}
|
||||
|
||||
//expect time_str as a friendly string format
|
||||
time_t get_time_from_str_as_gmt(char *time_str)
|
||||
time_t get_time_from_str_as_gmt(char* time_str)
|
||||
{
|
||||
struct tm val_time_tm;
|
||||
time_t val_time_t;
|
||||
@@ -68,7 +68,8 @@ time_t get_time_as_local(time_t time_t_val, char time_str[], int char_buf_size)
|
||||
{
|
||||
struct tm loc_time_tm;
|
||||
loc_time_tm = *localtime(&time_t_val);
|
||||
if (time_str != NULL) {
|
||||
if (time_str != NULL)
|
||||
{
|
||||
//debugf(DBG_LEVEL_NORM, 0,"Local len=%d size=%d pass=%d", strlen(time_str), sizeof(time_str), char_buf_size);
|
||||
strftime(time_str, char_buf_size, "%c", &loc_time_tm);
|
||||
//debugf(DBG_LEVEL_NORM, 0,"Local timestr=[%s] size=%d", time_str, strlen(time_str));
|
||||
@@ -77,19 +78,24 @@ time_t get_time_as_local(time_t time_t_val, char time_str[], int char_buf_size)
|
||||
return mktime(&loc_time_tm);
|
||||
}
|
||||
|
||||
int get_time_as_string(time_t time_t_val, long nsec, char *time_str, int time_str_len)
|
||||
int get_time_as_string(time_t time_t_val, long nsec, char* time_str,
|
||||
int time_str_len)
|
||||
{
|
||||
struct tm time_val_tm;
|
||||
time_t safe_input_time;
|
||||
//if time is incorrect (too long) you get segfault, need to check length and trim
|
||||
if (time_t_val > INT_MAX) {
|
||||
debugf(DBG_LEVEL_NORM, KRED"get_time_as_string: input time length too long, %lu > max=%lu, trimming!", time_t_val, INT_MAX);
|
||||
if (time_t_val > INT_MAX)
|
||||
{
|
||||
debugf(DBG_LEVEL_NORM,
|
||||
KRED"get_time_as_string: input time length too long, %lu > max=%lu, trimming!",
|
||||
time_t_val, INT_MAX);
|
||||
safe_input_time = 0;//(int)time_t_val;
|
||||
}
|
||||
else
|
||||
else
|
||||
safe_input_time = time_t_val;
|
||||
time_val_tm = *gmtime(&safe_input_time);
|
||||
int str_len = strftime(time_str, time_str_len, HUBIC_DATE_FORMAT, &time_val_tm);
|
||||
int str_len = strftime(time_str, time_str_len, HUBIC_DATE_FORMAT,
|
||||
&time_val_tm);
|
||||
char nsec_str[TIME_CHARS];
|
||||
sprintf(nsec_str, "%d", nsec);
|
||||
strcat(time_str, nsec_str);
|
||||
@@ -103,7 +109,7 @@ time_t get_time_now()
|
||||
return now.tv_sec;
|
||||
}
|
||||
|
||||
size_t get_time_now_as_str(char *time_str, int time_str_len)
|
||||
size_t get_time_now_as_str(char* time_str, int time_str_len)
|
||||
{
|
||||
time_t now = time(0);
|
||||
struct tm tstruct;
|
||||
@@ -114,44 +120,46 @@ size_t get_time_now_as_str(char *time_str, int time_str_len)
|
||||
return result;
|
||||
}
|
||||
|
||||
int get_timespec_as_str(const struct timespec *times, char *time_str, int time_str_len)
|
||||
int get_timespec_as_str(const struct timespec* times, char* time_str,
|
||||
int time_str_len)
|
||||
{
|
||||
return get_time_as_string(times->tv_sec, times->tv_nsec, time_str, time_str_len);
|
||||
return get_time_as_string(times->tv_sec, times->tv_nsec, time_str,
|
||||
time_str_len);
|
||||
}
|
||||
|
||||
char *str2md5(const char *str, int length)
|
||||
char* str2md5(const char* str, int length)
|
||||
{
|
||||
int n;
|
||||
MD5_CTX c;
|
||||
unsigned char digest[16];
|
||||
char *out = (char*)malloc(33);
|
||||
char* out = (char*)malloc(33);
|
||||
|
||||
MD5_Init(&c);
|
||||
while (length > 0) {
|
||||
if (length > 512) {
|
||||
while (length > 0)
|
||||
{
|
||||
if (length > 512)
|
||||
MD5_Update(&c, str, 512);
|
||||
}
|
||||
else {
|
||||
else
|
||||
MD5_Update(&c, str, length);
|
||||
}
|
||||
length -= 512;
|
||||
str += 512;
|
||||
}
|
||||
MD5_Final(digest, &c);
|
||||
for (n = 0; n < 16; ++n) {
|
||||
for (n = 0; n < 16; ++n)
|
||||
snprintf(&(out[n * 2]), 16 * 2, "%02x", (unsigned int)digest[n]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// http://stackoverflow.com/questions/10324611/how-to-calculate-the-md5-hash-of-a-large-file-in-c
|
||||
int file_md5(FILE *file_handle, char *md5_file_str)
|
||||
int file_md5(FILE* file_handle, char* md5_file_str)
|
||||
{
|
||||
if (file_handle == NULL) {
|
||||
if (file_handle == NULL)
|
||||
{
|
||||
debugf(DBG_LEVEL_NORM, KRED"file_md5: NULL file handle");
|
||||
return 0;
|
||||
}
|
||||
if (file_buffer_size == 0) {
|
||||
if (file_buffer_size == 0)
|
||||
{
|
||||
debugf(DBG_LEVEL_NORM, KYEL"file_md5: 0 file buffer size, using default");
|
||||
file_buffer_size = 1024;
|
||||
}
|
||||
@@ -160,12 +168,13 @@ int file_md5(FILE *file_handle, char *md5_file_str)
|
||||
MD5_CTX mdContext;
|
||||
int bytes;
|
||||
char mdchar[3];//2 chars for md5 + null string terminator
|
||||
unsigned char *data_buf = malloc(file_buffer_size * sizeof(unsigned char));
|
||||
unsigned char* data_buf = malloc(file_buffer_size * sizeof(unsigned char));
|
||||
MD5_Init(&mdContext);
|
||||
while ((bytes = fread(data_buf, 1, file_buffer_size, file_handle)) != 0)
|
||||
MD5_Update(&mdContext, data_buf, bytes);
|
||||
MD5_Final(c, &mdContext);
|
||||
for (i = 0; i < MD5_DIGEST_LENGTH; i++) {
|
||||
for (i = 0; i < MD5_DIGEST_LENGTH; i++)
|
||||
{
|
||||
snprintf(mdchar, 3, "%02x", c[i]);
|
||||
strcat(md5_file_str, mdchar);
|
||||
}
|
||||
@@ -173,14 +182,14 @@ int file_md5(FILE *file_handle, char *md5_file_str)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_safe_cache_file_path(const char *path, char *file_path_safe, char *temp_dir)
|
||||
int get_safe_cache_file_path(const char* path, char* file_path_safe,
|
||||
char* temp_dir)
|
||||
{
|
||||
char tmp_path[PATH_MAX];
|
||||
strncpy(tmp_path, path, PATH_MAX);
|
||||
char *pch;
|
||||
while ((pch = strchr(tmp_path, '/'))) {
|
||||
*pch = '.';
|
||||
}
|
||||
char* pch;
|
||||
while ((pch = strchr(tmp_path, '/')))
|
||||
* pch = '.';
|
||||
char file_path[PATH_MAX] = "";
|
||||
//temp file name had process pid in it, removed as on restart files are left in cache (pid changes)
|
||||
snprintf(file_path, PATH_MAX, TEMP_FILE_NAME_FORMAT, temp_dir, tmp_path);
|
||||
@@ -188,7 +197,7 @@ int get_safe_cache_file_path(const char *path, char *file_path_safe, char *temp_
|
||||
int file_path_len = sizeof(file_path);
|
||||
//the file path name using this format can go beyond NAME_MAX size and will generate error on fopen
|
||||
//solution: cap file length to NAME_MAX, use a prefix from original path for debug purposes and add md5 id
|
||||
char *md5_path = str2md5(file_path, file_path_len);
|
||||
char* md5_path = str2md5(file_path, file_path_len);
|
||||
int md5len = strlen(md5_path);
|
||||
size_t safe_len_prefix = min(NAME_MAX - md5len, file_path_len);
|
||||
strncpy(file_path_safe, file_path, safe_len_prefix);
|
||||
@@ -199,7 +208,7 @@ int get_safe_cache_file_path(const char *path, char *file_path_safe, char *temp_
|
||||
return strlen(file_path_safe);
|
||||
}
|
||||
|
||||
void get_file_path_from_fd(int fd, char *path, int size_path)
|
||||
void get_file_path_from_fd(int fd, char* path, int size_path)
|
||||
{
|
||||
char proc_path[MAX_PATH_SIZE];
|
||||
/* Read out the link to our file descriptor. */
|
||||
@@ -221,57 +230,60 @@ void debug_print_flags(int flags)
|
||||
if (val & O_APPEND) debugf(DBG_LEVEL_EXTALL, KYEL", append");
|
||||
if (val & O_NONBLOCK) debugf(DBG_LEVEL_EXTALL, KYEL", nonblocking");
|
||||
#if !defined(_POSIX_SOURCE) && defined(O_SYNC)
|
||||
if (val & O_SYNC) debugf(DBG_LEVEL_EXT, 0,KRED ", synchronous writes");
|
||||
if (val & O_SYNC) debugf(DBG_LEVEL_EXT, 0,
|
||||
KRED ", synchronous writes");
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
//for file descriptor debugging
|
||||
void debug_print_descriptor(struct fuse_file_info *info)
|
||||
void debug_print_descriptor(struct fuse_file_info* info)
|
||||
{
|
||||
char file_path[MAX_PATH_SIZE];
|
||||
get_file_path_from_fd(info->fh, file_path, sizeof(file_path));
|
||||
debugf(DBG_LEVEL_EXT, KCYN "descriptor localfile=[%s] fd=%d", file_path, info->fh);
|
||||
debugf(DBG_LEVEL_EXT, KCYN "descriptor localfile=[%s] fd=%d", file_path,
|
||||
info->fh);
|
||||
debug_print_flags(info->flags);
|
||||
}
|
||||
|
||||
void dir_for(const char *path, char *dir)
|
||||
void dir_for(const char* path, char* dir)
|
||||
{
|
||||
strncpy(dir, path, MAX_PATH_SIZE);
|
||||
char *slash = strrchr(dir, '/');
|
||||
char* slash = strrchr(dir, '/');
|
||||
if (slash)
|
||||
*slash = '\0';
|
||||
}
|
||||
|
||||
//prints cache content for debug purposes
|
||||
void debug_list_cache_content() {
|
||||
void debug_list_cache_content()
|
||||
{
|
||||
return;//disabled
|
||||
dir_cache *cw;
|
||||
dir_entry *de;
|
||||
dir_cache* cw;
|
||||
dir_entry* de;
|
||||
for (cw = dcache; cw; cw = cw->next)
|
||||
{
|
||||
debugf(DBG_LEVEL_EXT, "LIST-CACHE: DIR[%s]", cw->path);
|
||||
for (de = cw->entries; de; de = de->next) {
|
||||
for (de = cw->entries; de; de = de->next)
|
||||
debugf(DBG_LEVEL_EXT, "LIST-CACHE: FOLDER[%s]", de->full_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int delete_file(char *path)
|
||||
int delete_file(char* path)
|
||||
{
|
||||
debugf(DBG_LEVEL_NORM, KYEL"delete_file(%s)", path);
|
||||
char file_path_safe[NAME_MAX] = "";
|
||||
get_safe_cache_file_path(path, file_path_safe, temp_dir);
|
||||
int result = unlink(file_path_safe);
|
||||
debugf(DBG_LEVEL_EXT, KYEL"delete_file(%s) (%s) result=%s", path, file_path_safe, strerror(result));
|
||||
debugf(DBG_LEVEL_EXT, KYEL"delete_file(%s) (%s) result=%s", path,
|
||||
file_path_safe, strerror(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
//adding a directory in cache
|
||||
dir_cache *new_cache(const char *path)
|
||||
dir_cache* new_cache(const char* path)
|
||||
{
|
||||
debugf(DBG_LEVEL_NORM, KCYN"new_cache(%s)", path);
|
||||
dir_cache *cw = (dir_cache *)calloc(sizeof(dir_cache), 1);
|
||||
dir_cache* cw = (dir_cache*)calloc(sizeof(dir_cache), 1);
|
||||
cw->path = strdup(path);
|
||||
cw->prev = NULL;
|
||||
cw->entries = NULL;
|
||||
@@ -282,20 +294,21 @@ dir_cache *new_cache(const char *path)
|
||||
if (dcache)
|
||||
dcache->prev = cw;
|
||||
cw->next = dcache;
|
||||
dir_cache *result;
|
||||
dir_cache* result;
|
||||
result = (dcache = cw);
|
||||
debugf(DBG_LEVEL_EXT, "exit: new_cache(%s)", path);
|
||||
return result;
|
||||
}
|
||||
|
||||
//todo: check if the program behaves ok when free_dir
|
||||
//todo: check if the program behaves ok when free_dir
|
||||
//is made on a folder that has an operation in progress
|
||||
void cloudfs_free_dir_list(dir_entry *dir_list)
|
||||
void cloudfs_free_dir_list(dir_entry* dir_list)
|
||||
{
|
||||
//check for NULL as dir might be already removed from cache by other thread
|
||||
debugf(DBG_LEVEL_NORM, "cloudfs_free_dir_list(%s)", dir_list->full_name);
|
||||
while (dir_list) {
|
||||
dir_entry *de = dir_list;
|
||||
while (dir_list)
|
||||
{
|
||||
dir_entry* de = dir_list;
|
||||
dir_list = dir_list->next;
|
||||
//remove file from disk cache, fix for issue #89, https://github.com/TurboGit/hubicfuse/issues/89
|
||||
delete_file(de->full_name);
|
||||
@@ -308,15 +321,16 @@ void cloudfs_free_dir_list(dir_entry *dir_list)
|
||||
}
|
||||
}
|
||||
|
||||
void dir_decache(const char *path)
|
||||
void dir_decache(const char* path)
|
||||
{
|
||||
dir_cache *cw;
|
||||
dir_cache* cw;
|
||||
debugf(DBG_LEVEL_NORM, "dir_decache(%s)", path);
|
||||
pthread_mutex_lock(&dcachemut);
|
||||
dir_entry *de, *tmpde;
|
||||
dir_entry* de, *tmpde;
|
||||
char dir[MAX_PATH_SIZE];
|
||||
dir_for(path, dir);
|
||||
for (cw = dcache; cw; cw = cw->next) {
|
||||
for (cw = dcache; cw; cw = cw->next)
|
||||
{
|
||||
debugf(DBG_LEVEL_EXT, "dir_decache: parse(%s)", cw->path);
|
||||
if (!strcmp(cw->path, path))
|
||||
{
|
||||
@@ -344,17 +358,17 @@ void dir_decache(const char *path)
|
||||
cloudfs_free_dir_list(de);
|
||||
}
|
||||
else for (de = cw->entries; de->next; de = de->next)
|
||||
{
|
||||
if (!strcmp(de->next->full_name, path))
|
||||
{
|
||||
tmpde = de->next;
|
||||
de->next = de->next->next;
|
||||
tmpde->next = NULL;
|
||||
debugf(DBG_LEVEL_EXT, "dir_decache: free_dir3()", cw->path);
|
||||
cloudfs_free_dir_list(tmpde);
|
||||
break;
|
||||
if (!strcmp(de->next->full_name, path))
|
||||
{
|
||||
tmpde = de->next;
|
||||
de->next = de->next->next;
|
||||
tmpde->next = NULL;
|
||||
debugf(DBG_LEVEL_EXT, "dir_decache: free_dir3()", cw->path);
|
||||
cloudfs_free_dir_list(tmpde);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&dcachemut);
|
||||
@@ -362,7 +376,7 @@ void dir_decache(const char *path)
|
||||
|
||||
dir_entry* init_dir_entry()
|
||||
{
|
||||
dir_entry *de = (dir_entry *)malloc(sizeof(dir_entry));
|
||||
dir_entry* de = (dir_entry*)malloc(sizeof(dir_entry));
|
||||
de->metadata_downloaded = false;
|
||||
de->size = 0;
|
||||
de->next = NULL;
|
||||
@@ -381,7 +395,7 @@ dir_entry* init_dir_entry()
|
||||
return de;
|
||||
}
|
||||
|
||||
void copy_dir_entry(dir_entry *src, dir_entry *dst)
|
||||
void copy_dir_entry(dir_entry* src, dir_entry* dst)
|
||||
{
|
||||
dst->atime.tv_sec = src->atime.tv_sec;
|
||||
dst->atime.tv_nsec = src->atime.tv_nsec;
|
||||
@@ -392,15 +406,15 @@ void copy_dir_entry(dir_entry *src, dir_entry *dst)
|
||||
dst->chmod = src->chmod;
|
||||
//todo: copy md5sum as well
|
||||
}
|
||||
|
||||
//check for file in cache, if found size will be updated, if not found
|
||||
|
||||
//check for file in cache, if found size will be updated, if not found
|
||||
//and this is a dir, a new dir cache entry is created
|
||||
void update_dir_cache(const char *path, off_t size, int isdir, int islink)
|
||||
void update_dir_cache(const char* path, off_t size, int isdir, int islink)
|
||||
{
|
||||
debugf(DBG_LEVEL_EXTALL, KCYN "update_dir_cache(%s)", path);
|
||||
pthread_mutex_lock(&dcachemut);
|
||||
dir_cache *cw;
|
||||
dir_entry *de;
|
||||
dir_cache* cw;
|
||||
dir_entry* de;
|
||||
char dir[MAX_PATH_SIZE];
|
||||
dir_for(path, dir);
|
||||
for (cw = dcache; cw; cw = cw->next)
|
||||
@@ -413,7 +427,7 @@ void update_dir_cache(const char *path, off_t size, int isdir, int islink)
|
||||
{
|
||||
de->size = size;
|
||||
pthread_mutex_unlock(&dcachemut);
|
||||
debugf(DBG_LEVEL_EXTALL, "exit 0: update_dir_cache(%s)", path);
|
||||
debugf(DBG_LEVEL_EXTALL, "exit 0: update_dir_cache(%s)", path);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -424,17 +438,12 @@ void update_dir_cache(const char *path, off_t size, int isdir, int islink)
|
||||
de->name = strdup(&path[strlen(cw->path) + 1]);
|
||||
de->full_name = strdup(path);
|
||||
//fixed: the conditions below were mixed up dir -> link?
|
||||
if (islink)
|
||||
{
|
||||
if (islink)
|
||||
de->content_type = strdup("application/link");
|
||||
}
|
||||
if (isdir)
|
||||
{
|
||||
if (isdir)
|
||||
de->content_type = strdup("application/directory");
|
||||
}
|
||||
else {
|
||||
else
|
||||
de->content_type = strdup("application/octet-stream");
|
||||
}
|
||||
de->next = cw->entries;
|
||||
cw->entries = de;
|
||||
if (isdir)
|
||||
@@ -447,25 +456,28 @@ void update_dir_cache(const char *path, off_t size, int isdir, int islink)
|
||||
}
|
||||
|
||||
//returns first file entry in linked list. if not in cache will be downloaded.
|
||||
int caching_list_directory(const char *path, dir_entry **list)
|
||||
int caching_list_directory(const char* path, dir_entry** list)
|
||||
{
|
||||
debugf(DBG_LEVEL_EXT, "caching_list_directory(%s)", path);
|
||||
pthread_mutex_lock(&dcachemut);
|
||||
bool new_entry = false;
|
||||
if (!strcmp(path, "/"))
|
||||
path = "";
|
||||
dir_cache *cw;
|
||||
for (cw = dcache; cw; cw = cw->next)
|
||||
dir_cache* cw;
|
||||
for (cw = dcache; cw; cw = cw->next)
|
||||
{
|
||||
if (cw->was_deleted == true)
|
||||
{
|
||||
debugf(DBG_LEVEL_EXT, KMAG"caching_list_directory status: dir(%s) is empty as cached expired, reload from cloud", cw->path);
|
||||
debugf(DBG_LEVEL_EXT,
|
||||
KMAG"caching_list_directory status: dir(%s) is empty as cached expired, reload from cloud",
|
||||
cw->path);
|
||||
if (!cloudfs_list_directory(cw->path, list))
|
||||
debugf(DBG_LEVEL_EXT,
|
||||
KMAG"caching_list_directory status: cannot reload dir(%s)", cw->path);
|
||||
else
|
||||
{
|
||||
debugf(DBG_LEVEL_EXT, KMAG"caching_list_directory status: cannot reload dir(%s)", cw->path);
|
||||
}
|
||||
else {
|
||||
debugf(DBG_LEVEL_EXT, KMAG"caching_list_directory status: reloaded dir(%s)", cw->path);
|
||||
debugf(DBG_LEVEL_EXT, KMAG"caching_list_directory status: reloaded dir(%s)",
|
||||
cw->path);
|
||||
//cw->entries = *list;
|
||||
cw->was_deleted = false;
|
||||
cw->cached = time(NULL);
|
||||
@@ -474,9 +486,7 @@ int caching_list_directory(const char *path, dir_entry **list)
|
||||
if (cw->was_deleted == false)
|
||||
{
|
||||
if (!strcmp(cw->path, path))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!cw)
|
||||
@@ -486,10 +496,12 @@ int caching_list_directory(const char *path, dir_entry **list)
|
||||
{
|
||||
//download was not ok
|
||||
pthread_mutex_unlock(&dcachemut);
|
||||
debugf(DBG_LEVEL_EXT, "exit 0: caching_list_directory(%s) "KYEL"[CACHE-DIR-MISS]", path);
|
||||
debugf(DBG_LEVEL_EXT,
|
||||
"exit 0: caching_list_directory(%s) "KYEL"[CACHE-DIR-MISS]", path);
|
||||
return 0;
|
||||
}
|
||||
debugf(DBG_LEVEL_EXT, "caching_list_directory: new_cache(%s) "KYEL"[CACHE-CREATE]", path);
|
||||
debugf(DBG_LEVEL_EXT,
|
||||
"caching_list_directory: new_cache(%s) "KYEL"[CACHE-CREATE]", path);
|
||||
cw = new_cache(path);
|
||||
new_entry = true;
|
||||
}
|
||||
@@ -509,16 +521,21 @@ int caching_list_directory(const char *path, dir_entry **list)
|
||||
cloudfs_free_dir_list(cw->entries);
|
||||
cw->was_deleted = true;
|
||||
cw->cached = time(NULL);
|
||||
debugf(DBG_LEVEL_EXT, "caching_list_directory(%s) "KYEL"[CACHE-EXPIRED]", path);
|
||||
debugf(DBG_LEVEL_EXT, "caching_list_directory(%s) "KYEL"[CACHE-EXPIRED]",
|
||||
path);
|
||||
}
|
||||
else {
|
||||
debugf(DBG_LEVEL_EXT, "got NULL on caching_list_directory(%s) "KYEL"[CACHE-EXPIRED w NULL]", path);
|
||||
else
|
||||
{
|
||||
debugf(DBG_LEVEL_EXT,
|
||||
"got NULL on caching_list_directory(%s) "KYEL"[CACHE-EXPIRED w NULL]", path);
|
||||
pthread_mutex_unlock(&dcachemut);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
debugf(DBG_LEVEL_EXT, "caching_list_directory(%s) "KGRN"[CACHE-DIR-HIT]", path);
|
||||
else
|
||||
{
|
||||
debugf(DBG_LEVEL_EXT, "caching_list_directory(%s) "KGRN"[CACHE-DIR-HIT]",
|
||||
path);
|
||||
*list = cw->entries;
|
||||
}
|
||||
//adding new dir file list to global cache, now this dir becomes visible in cache
|
||||
@@ -528,20 +545,19 @@ int caching_list_directory(const char *path, dir_entry **list)
|
||||
return 1;
|
||||
}
|
||||
|
||||
dir_entry *path_info(const char *path)
|
||||
dir_entry* path_info(const char* path)
|
||||
{
|
||||
debugf(DBG_LEVEL_EXT, "path_info(%s)", path);
|
||||
char dir[MAX_PATH_SIZE];
|
||||
dir_for(path, dir);
|
||||
dir_entry *tmp;
|
||||
dir_entry* tmp;
|
||||
if (!caching_list_directory(dir, &tmp))
|
||||
{
|
||||
debugf(DBG_LEVEL_EXT, "exit 0: path_info(%s) "KYEL"[CACHE-DIR-MISS]", dir);
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
else
|
||||
debugf(DBG_LEVEL_EXT, "path_info(%s) "KGRN"[CACHE-DIR-HIT]", dir);
|
||||
}
|
||||
//iterate in file list obtained from cache or downloaded
|
||||
for (; tmp; tmp = tmp->next)
|
||||
{
|
||||
@@ -558,31 +574,33 @@ dir_entry *path_info(const char *path)
|
||||
|
||||
|
||||
//retrieve folder from local cache if exists, return null if does not exist (rather than download)
|
||||
int check_caching_list_directory(const char *path, dir_entry **list)
|
||||
int check_caching_list_directory(const char* path, dir_entry** list)
|
||||
{
|
||||
debugf(DBG_LEVEL_EXT, "check_caching_list_directory(%s)", path);
|
||||
pthread_mutex_lock(&dcachemut);
|
||||
if (!strcmp(path, "/"))
|
||||
path = "";
|
||||
dir_cache *cw;
|
||||
dir_cache* cw;
|
||||
for (cw = dcache; cw; cw = cw->next)
|
||||
if (!strcmp(cw->path, path))
|
||||
{
|
||||
*list = cw->entries;
|
||||
pthread_mutex_unlock(&dcachemut);
|
||||
debugf(DBG_LEVEL_EXT, "exit 0: check_caching_list_directory(%s) "KGRN"[CACHE-DIR-HIT]", path);
|
||||
debugf(DBG_LEVEL_EXT,
|
||||
"exit 0: check_caching_list_directory(%s) "KGRN"[CACHE-DIR-HIT]", path);
|
||||
return 1;
|
||||
}
|
||||
pthread_mutex_unlock(&dcachemut);
|
||||
debugf(DBG_LEVEL_EXT, "exit 1: check_caching_list_directory(%s) "KYEL"[CACHE-DIR-MISS]", path);
|
||||
debugf(DBG_LEVEL_EXT,
|
||||
"exit 1: check_caching_list_directory(%s) "KYEL"[CACHE-DIR-MISS]", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
dir_entry * check_parent_folder_for_file(const char *path)
|
||||
dir_entry* check_parent_folder_for_file(const char* path)
|
||||
{
|
||||
char dir[MAX_PATH_SIZE];
|
||||
dir_for(path, dir);
|
||||
dir_entry *tmp;
|
||||
dir_entry* tmp;
|
||||
if (!check_caching_list_directory(dir, &tmp))
|
||||
return NULL;
|
||||
else
|
||||
@@ -590,12 +608,12 @@ dir_entry * check_parent_folder_for_file(const char *path)
|
||||
}
|
||||
|
||||
//check if local path is in cache, without downloading from cloud if not in cache
|
||||
dir_entry *check_path_info(const char *path)
|
||||
dir_entry* check_path_info(const char* path)
|
||||
{
|
||||
debugf(DBG_LEVEL_EXT, "check_path_info(%s)", path);
|
||||
char dir[MAX_PATH_SIZE];
|
||||
dir_for(path, dir);
|
||||
dir_entry *tmp;
|
||||
dir_entry* tmp;
|
||||
|
||||
//get parent folder cache entry
|
||||
if (!check_caching_list_directory(dir, &tmp))
|
||||
@@ -612,22 +630,20 @@ dir_entry *check_path_info(const char *path)
|
||||
}
|
||||
}
|
||||
if (!strcmp(path, "/"))
|
||||
{
|
||||
debugf(DBG_LEVEL_EXT, "exit 2: check_path_info(%s) "KYEL"ignoring root [CACHE-MISS]", path);
|
||||
}
|
||||
else {
|
||||
debugf(DBG_LEVEL_EXT,
|
||||
"exit 2: check_path_info(%s) "KYEL"ignoring root [CACHE-MISS]", path);
|
||||
else
|
||||
debugf(DBG_LEVEL_EXT, "exit 3: check_path_info(%s) "KYEL"[CACHE-MISS]", path);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char *get_home_dir()
|
||||
char* get_home_dir()
|
||||
{
|
||||
char *home;
|
||||
char* home;
|
||||
if ((home = getenv("HOME")) && !access(home, R_OK))
|
||||
return home;
|
||||
struct passwd *pwd = getpwuid(geteuid());
|
||||
struct passwd* pwd = getpwuid(geteuid());
|
||||
if ((home = pwd->pw_dir) && !access(home, R_OK))
|
||||
return home;
|
||||
return "~";
|
||||
@@ -638,15 +654,15 @@ void cloudfs_debug(int dbg)
|
||||
debug = dbg;
|
||||
}
|
||||
|
||||
void debugf(int level, char *fmt, ...)
|
||||
void debugf(int level, char* fmt, ...)
|
||||
{
|
||||
if (debug)
|
||||
if (debug)
|
||||
{
|
||||
if (level <= option_debug_level)
|
||||
{
|
||||
#ifdef SYS_gettid
|
||||
pid_t thread_id = syscall(SYS_gettid);
|
||||
#else
|
||||
#else
|
||||
int thread_id = 0;
|
||||
#error "SYS_gettid unavailable on this system"
|
||||
#endif
|
||||
|
||||
+35
-31
@@ -44,16 +44,16 @@ typedef enum { false, true } bool;
|
||||
//linked list with files in a directory
|
||||
typedef struct dir_entry
|
||||
{
|
||||
char *name;
|
||||
char *full_name;
|
||||
char *content_type;
|
||||
char* name;
|
||||
char* full_name;
|
||||
char* content_type;
|
||||
off_t size;
|
||||
time_t last_modified;
|
||||
// implement utimens
|
||||
struct timespec mtime;
|
||||
struct timespec ctime;
|
||||
struct timespec atime;
|
||||
char *md5sum; //interesting capability for rsync/scrub
|
||||
char* md5sum; //interesting capability for rsync/scrub
|
||||
mode_t chmod;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
@@ -63,47 +63,51 @@ typedef struct dir_entry
|
||||
// end change
|
||||
int isdir;
|
||||
int islink;
|
||||
struct dir_entry *next;
|
||||
struct dir_entry* next;
|
||||
} dir_entry;
|
||||
|
||||
// linked list with cached folder names
|
||||
typedef struct dir_cache
|
||||
{
|
||||
char *path;
|
||||
dir_entry *entries;
|
||||
char* path;
|
||||
dir_entry* entries;
|
||||
time_t cached;
|
||||
//added cache support based on access time
|
||||
time_t accessed_in_cache;
|
||||
bool was_deleted;
|
||||
//end change
|
||||
struct dir_cache *next, *prev;
|
||||
struct dir_cache* next, *prev;
|
||||
} dir_cache;
|
||||
|
||||
time_t my_timegm(struct tm *tm);
|
||||
time_t get_time_from_str_as_gmt(char *time_str);
|
||||
time_t get_time_as_local(time_t time_t_val, char time_str[], int char_buf_size);
|
||||
int get_time_as_string(time_t time_t_val, long nsec, char *time_str, int time_str_len);
|
||||
time_t my_timegm(struct tm* tm);
|
||||
time_t get_time_from_str_as_gmt(char* time_str);
|
||||
time_t get_time_as_local(time_t time_t_val, char time_str[],
|
||||
int char_buf_size);
|
||||
int get_time_as_string(time_t time_t_val, long nsec, char* time_str,
|
||||
int time_str_len);
|
||||
time_t get_time_now();
|
||||
int get_timespec_as_str(const struct timespec *times, char *time_str, int time_str_len);
|
||||
char *str2md5(const char *str, int length);
|
||||
int file_md5(FILE *file_handle, char *md5_file_str);
|
||||
void debug_print_descriptor(struct fuse_file_info *info);
|
||||
int get_safe_cache_file_path(const char *file_path, char *file_path_safe, char *temp_dir);
|
||||
dir_entry *init_dir_entry();
|
||||
void copy_dir_entry(dir_entry *src, dir_entry *dst);
|
||||
dir_cache *new_cache(const char *path);
|
||||
void dir_for(const char *path, char *dir);
|
||||
int get_timespec_as_str(const struct timespec* times, char* time_str,
|
||||
int time_str_len);
|
||||
char* str2md5(const char* str, int length);
|
||||
int file_md5(FILE* file_handle, char* md5_file_str);
|
||||
void debug_print_descriptor(struct fuse_file_info* info);
|
||||
int get_safe_cache_file_path(const char* file_path, char* file_path_safe,
|
||||
char* temp_dir);
|
||||
dir_entry* init_dir_entry();
|
||||
void copy_dir_entry(dir_entry* src, dir_entry* dst);
|
||||
dir_cache* new_cache(const char* path);
|
||||
void dir_for(const char* path, char* dir);
|
||||
void debug_list_cache_content();
|
||||
void update_dir_cache(const char *path, off_t size, int isdir, int islink);
|
||||
dir_entry *path_info(const char *path);
|
||||
dir_entry *check_path_info(const char *path);
|
||||
dir_entry * check_parent_folder_for_file(const char *path);
|
||||
void dir_decache(const char *path);
|
||||
void cloudfs_free_dir_list(dir_entry *dir_list);
|
||||
extern int cloudfs_list_directory(const char *path, dir_entry **);
|
||||
int caching_list_directory(const char *path, dir_entry **list);
|
||||
char *get_home_dir();
|
||||
void update_dir_cache(const char* path, off_t size, int isdir, int islink);
|
||||
dir_entry* path_info(const char* path);
|
||||
dir_entry* check_path_info(const char* path);
|
||||
dir_entry* check_parent_folder_for_file(const char* path);
|
||||
void dir_decache(const char* path);
|
||||
void cloudfs_free_dir_list(dir_entry* dir_list);
|
||||
extern int cloudfs_list_directory(const char* path, dir_entry**);
|
||||
int caching_list_directory(const char* path, dir_entry** list);
|
||||
char* get_home_dir();
|
||||
void cloudfs_debug(int dbg);
|
||||
void debugf(int level, char *fmt, ...);
|
||||
void debugf(int level, char* fmt, ...);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user