Path: blob/main/filesystems/curlftpfs/files/patch-ftpfs.c
16464 views
--- ftpfs.c.orig 2008-04-29 23:05:47 UTC1+++ ftpfs.c2@@ -257,6 +257,7 @@ static int ftpfs_getdir(const char* path, fuse_cache_d3int err = 0;4CURLcode curl_res;5char* dir_path = get_fulldir_path(path);6+ char* dir_path_uri = path_to_uri(dir_path);78DEBUG(1, "ftpfs_getdir: %s\n", dir_path);9struct buffer buf;10@@ -264,7 +265,7 @@ static int ftpfs_getdir(const char* path, fuse_cache_d1112pthread_mutex_lock(&ftpfs.lock);13cancel_previous_multi();14- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, dir_path);15+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, dir_path_uri);16curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);17curl_res = curl_easy_perform(ftpfs.connection);18pthread_mutex_unlock(&ftpfs.lock);19@@ -278,6 +279,7 @@ static int ftpfs_getdir(const char* path, fuse_cache_d20NULL, NULL, NULL, 0, h, filler);21}2223+ free_uri(dir_path_uri);24free(dir_path);25buf_free(&buf);26return op_return(err, "ftpfs_getdir");27@@ -287,6 +289,7 @@ static int ftpfs_getattr(const char* path, struct stat28int err;29CURLcode curl_res;30char* dir_path = get_dir_path(path);31+ char* dir_path_uri = path_to_uri(dir_path);3233DEBUG(2, "ftpfs_getattr: %s dir_path=%s\n", path, dir_path);34struct buffer buf;35@@ -294,7 +297,7 @@ static int ftpfs_getattr(const char* path, struct stat3637pthread_mutex_lock(&ftpfs.lock);38cancel_previous_multi();39- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, dir_path);40+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, dir_path_uri);41curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);42curl_res = curl_easy_perform(ftpfs.connection);43pthread_mutex_unlock(&ftpfs.lock);44@@ -309,6 +312,7 @@ static int ftpfs_getattr(const char* path, struct stat45err = parse_dir((char*)buf.p, dir_path + strlen(ftpfs.host) - 1,46name, sbuf, NULL, 0, NULL, NULL);4748+ free_uri(dir_path_uri);49free(dir_path);50buf_free(&buf);51if (err) return op_return(-ENOENT, "ftpfs_getattr");52@@ -329,6 +333,7 @@ static size_t ftpfs_read_chunk(const char* full_path,53int running_handles = 0;54int err = 0;55struct ftpfs_file* fh = get_ftpfs_file(fi);56+ char* full_path_uri = path_to_uri(full_path); /* TODO: optimize bu pushing up conversion to context */5758DEBUG(2, "ftpfs_read_chunk: %s %p %zu %lld %p %p\n",59full_path, rbuf, size, offset, fi, fh);60@@ -355,7 +360,7 @@ static size_t ftpfs_read_chunk(const char* full_path,6162cancel_previous_multi();6364- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path);65+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);66curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &fh->buf);67if (offset) {68char range[15];69@@ -444,6 +449,7 @@ static size_t ftpfs_read_chunk(const char* full_path,7071pthread_mutex_unlock(&ftpfs.lock);7273+ free_uri(full_path_uri);74if (err) return CURLFTPFS_BAD_READ;75return size;76}77@@ -497,11 +503,12 @@ int write_thread_ctr = 0;78static void *ftpfs_write_thread(void *data) {79struct ftpfs_file *fh = data;80char range[15];81-82+ char* full_path_uri = path_to_uri(fh->full_path); /* TODO: optimize bu pushing up conversion to context */83+84DEBUG(2, "enter streaming write thread #%d path=%s pos=%lld\n", ++write_thread_ctr, fh->full_path, fh->pos);858687- curl_easy_setopt_or_die(fh->write_conn, CURLOPT_URL, fh->full_path);88+ curl_easy_setopt_or_die(fh->write_conn, CURLOPT_URL, full_path_uri);89curl_easy_setopt_or_die(fh->write_conn, CURLOPT_UPLOAD, 1);90curl_easy_setopt_or_die(fh->write_conn, CURLOPT_INFILESIZE, -1);91curl_easy_setopt_or_die(fh->write_conn, CURLOPT_READFUNCTION, write_data_bg);92@@ -541,6 +548,8 @@ static void *ftpfs_write_thread(void *data) {9394sem_post(&fh->data_written); /* ftpfs_write may return */9596+ free_uri(full_path_uri);97+98return NULL;99}100101@@ -619,16 +628,19 @@ static void free_ftpfs_file(struct ftpfs_file *fh) {102}103104static int buffer_file(struct ftpfs_file *fh) {105+ char* full_path_uri = path_to_uri(fh->full_path); /* TODO: optimize bu pushing up conversion to context */106// If we want to write to the file, we have to load it all at once,107// modify it in memory and then upload it as a whole as most FTP servers108// don't support resume for uploads.109pthread_mutex_lock(&ftpfs.lock);110cancel_previous_multi();111- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, fh->full_path);112+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);113curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &fh->buf);114CURLcode curl_res = curl_easy_perform(ftpfs.connection);115pthread_mutex_unlock(&ftpfs.lock);116117+ free_uri(full_path_uri);118+119if (curl_res != 0) {120return -EACCES;121}122@@ -641,10 +653,11 @@ static int create_empty_file(const char * path)123int err = 0;124125char *full_path = get_full_path(path);126+ char* full_path_uri = path_to_uri(full_path);127128pthread_mutex_lock(&ftpfs.lock);129cancel_previous_multi();130- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path);131+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);132curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_INFILESIZE, 0);133curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_UPLOAD, 1);134curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_READDATA, NULL);135@@ -654,7 +667,9 @@ static int create_empty_file(const char * path)136137if (curl_res != 0) {138err = -EPERM;139- }140+ }141+142+ free_uri(full_path_uri);143free(full_path);144return err;145}146@@ -873,6 +888,7 @@ static int ftpfs_chmod(const char* path, mode_t mode)147148struct curl_slist* header = NULL;149char* full_path = get_dir_path(path);150+ char* full_path_uri = path_to_uri(full_path);151char* filename = get_file_name(path);152char* cmd = g_strdup_printf("SITE CHMOD %.3o %s", mode_c, filename);153struct buffer buf;154@@ -883,7 +899,7 @@ static int ftpfs_chmod(const char* path, mode_t mode)155pthread_mutex_lock(&ftpfs.lock);156cancel_previous_multi();157curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_POSTQUOTE, header);158- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path);159+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);160curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);161curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_NOBODY, ftpfs.safe_nobody);162CURLcode curl_res = curl_easy_perform(ftpfs.connection);163@@ -894,12 +910,13 @@ static int ftpfs_chmod(const char* path, mode_t mode)164if (curl_res != 0) {165err = -EPERM;166}167-168+169buf_free(&buf);170curl_slist_free_all(header);171+ free_uri(full_path_uri);172free(full_path);173free(filename);174- free(cmd);175+ free(cmd);176return op_return(err, "ftpfs_chmod");177}178179@@ -910,6 +927,7 @@ static int ftpfs_chown(const char* path, uid_t uid, gi180181struct curl_slist* header = NULL;182char* full_path = get_dir_path(path);183+ char* full_path_uri = path_to_uri(full_path);184char* filename = get_file_name(path);185char* cmd = g_strdup_printf("SITE CHUID %i %s", uid, filename);186char* cmd2 = g_strdup_printf("SITE CHGID %i %s", gid, filename);187@@ -922,7 +940,7 @@ static int ftpfs_chown(const char* path, uid_t uid, gi188pthread_mutex_lock(&ftpfs.lock);189cancel_previous_multi();190curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_POSTQUOTE, header);191- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path);192+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);193curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);194curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_NOBODY, ftpfs.safe_nobody);195CURLcode curl_res = curl_easy_perform(ftpfs.connection);196@@ -936,6 +954,7 @@ static int ftpfs_chown(const char* path, uid_t uid, gi197198buf_free(&buf);199curl_slist_free_all(header);200+ free_uri(full_path_uri);201free(full_path);202free(filename);203free(cmd);204@@ -999,6 +1018,7 @@ static int ftpfs_rmdir(const char* path) {205int err = 0;206struct curl_slist* header = NULL;207char* full_path = get_dir_path(path);208+ char* full_path_uri = path_to_uri(full_path);209char* filename = get_file_name(path);210char* cmd = g_strdup_printf("RMD %s", filename);211struct buffer buf;212@@ -1012,7 +1032,7 @@ static int ftpfs_rmdir(const char* path) {213pthread_mutex_lock(&ftpfs.lock);214cancel_previous_multi();215curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_POSTQUOTE, header);216- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path);217+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);218curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);219curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_NOBODY, ftpfs.safe_nobody);220CURLcode curl_res = curl_easy_perform(ftpfs.connection);221@@ -1026,6 +1046,7 @@ static int ftpfs_rmdir(const char* path) {222223buf_free(&buf);224curl_slist_free_all(header);225+ free_uri(full_path_uri);226free(full_path);227free(filename);228free(cmd);229@@ -1036,6 +1057,7 @@ static int ftpfs_mkdir(const char* path, mode_t mode)230int err = 0;231struct curl_slist* header = NULL;232char* full_path = get_dir_path(path);233+ char* full_path_uri = path_to_uri(full_path);234char* filename = get_file_name(path);235char* cmd = g_strdup_printf("MKD %s", filename);236struct buffer buf;237@@ -1046,7 +1068,7 @@ static int ftpfs_mkdir(const char* path, mode_t mode)238pthread_mutex_lock(&ftpfs.lock);239cancel_previous_multi();240curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_POSTQUOTE, header);241- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path);242+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);243curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);244curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_NOBODY, ftpfs.safe_nobody);245CURLcode curl_res = curl_easy_perform(ftpfs.connection);246@@ -1060,6 +1082,7 @@ static int ftpfs_mkdir(const char* path, mode_t mode)247248buf_free(&buf);249curl_slist_free_all(header);250+ free_uri(full_path_uri);251free(full_path);252free(filename);253free(cmd);254@@ -1074,6 +1097,7 @@ static int ftpfs_unlink(const char* path) {255int err = 0;256struct curl_slist* header = NULL;257char* full_path = get_dir_path(path);258+ char* full_path_uri = path_to_uri(full_path);259char* filename = get_file_name(path);260char* cmd = g_strdup_printf("DELE %s", filename);261struct buffer buf;262@@ -1084,7 +1108,7 @@ static int ftpfs_unlink(const char* path) {263pthread_mutex_lock(&ftpfs.lock);264cancel_previous_multi();265curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_POSTQUOTE, header);266- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path);267+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, full_path_uri);268curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);269curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_NOBODY, ftpfs.safe_nobody);270CURLcode curl_res = curl_easy_perform(ftpfs.connection);271@@ -1098,6 +1122,7 @@ static int ftpfs_unlink(const char* path) {272273buf_free(&buf);274curl_slist_free_all(header);275+ free_uri(full_path_uri);276free(full_path);277free(filename);278free(cmd);279@@ -1299,6 +1324,7 @@ static int ftpfs_readlink(const char *path, char *link280int err;281CURLcode curl_res;282char* dir_path = get_dir_path(path);283+ char* dir_path_uri = path_to_uri(dir_path);284285DEBUG(2, "dir_path: %s %s\n", path, dir_path);286struct buffer buf;287@@ -1306,7 +1332,7 @@ static int ftpfs_readlink(const char *path, char *link288289pthread_mutex_lock(&ftpfs.lock);290cancel_previous_multi();291- curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, dir_path);292+ curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_URL, dir_path_uri);293curl_easy_setopt_or_die(ftpfs.connection, CURLOPT_WRITEDATA, &buf);294curl_res = curl_easy_perform(ftpfs.connection);295pthread_mutex_unlock(&ftpfs.lock);296@@ -1321,6 +1347,7 @@ static int ftpfs_readlink(const char *path, char *link297err = parse_dir((char*)buf.p, dir_path + strlen(ftpfs.host) - 1,298name, NULL, linkbuf, size, NULL, NULL);299300+ free_uri(dir_path_uri);301free(dir_path);302buf_free(&buf);303if (err) return op_return(-ENOENT, "ftpfs_readlink");304305306