mirror of
https://github.com/fangfufu/httpdirfs.git
synced 2024-09-27 20:51:55 +02:00
added timestamp support
This commit is contained in:
parent
c43c0cd345
commit
c1fcf109b0
5
main.c
5
main.c
@ -74,6 +74,9 @@ static int fs_getattr(const char *path, struct stat *stbuf)
|
|||||||
if (!link) {
|
if (!link) {
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
struct timespec spec;
|
||||||
|
spec.tv_sec = link->time;
|
||||||
|
stbuf->st_mtim = spec;
|
||||||
switch (link->type) {
|
switch (link->type) {
|
||||||
case LINK_DIR:
|
case LINK_DIR:
|
||||||
stbuf->st_mode = S_IFDIR | 0755;
|
stbuf->st_mode = S_IFDIR | 0755;
|
||||||
@ -88,8 +91,6 @@ static int fs_getattr(const char *path, struct stat *stbuf)
|
|||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
55
network.c
55
network.c
@ -18,7 +18,7 @@ typedef struct {
|
|||||||
} MemoryStruct;
|
} MemoryStruct;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
FILESIZE = 's',
|
FILESTAT = 's',
|
||||||
DATA = 'd'
|
DATA = 'd'
|
||||||
} TransferType;
|
} TransferType;
|
||||||
|
|
||||||
@ -43,11 +43,12 @@ static CURLM *curl_multi;
|
|||||||
|
|
||||||
/* Link related */
|
/* Link related */
|
||||||
static Link *Link_new(const char *p_url, LinkType type);
|
static Link *Link_new(const char *p_url, LinkType type);
|
||||||
static void Link_get_size(Link *this_link);
|
static void Link_get_stat(Link *this_link);
|
||||||
static Link *path_to_Link_recursive(char *path, LinkTable *linktbl);
|
static Link *path_to_Link_recursive(char *path, LinkTable *linktbl);
|
||||||
static CURL *Link_to_curl(Link *link);
|
static CURL *Link_to_curl(Link *link);
|
||||||
static LinkType p_url_type(const char *p_url);
|
static LinkType p_url_type(const char *p_url);
|
||||||
static char *url_append(const char *url, const char *sublink);
|
static char *url_append(const char *url, const char *sublink);
|
||||||
|
static void link_set_stat(Link* this_link, CURL *curl);
|
||||||
|
|
||||||
/* LinkTable related */
|
/* LinkTable related */
|
||||||
static void LinkTable_add(LinkTable *linktbl, Link *link);
|
static void LinkTable_add(LinkTable *linktbl, Link *link);
|
||||||
@ -170,29 +171,13 @@ static int curl_multi_perform_once()
|
|||||||
url);
|
url);
|
||||||
} else {
|
} else {
|
||||||
/* Transfer successful, query the file size */
|
/* Transfer successful, query the file size */
|
||||||
if (transfer->type == FILESIZE) {
|
if (transfer->type == FILESTAT) {
|
||||||
Link *this_link = transfer->link;
|
link_set_stat(transfer->link, curl);
|
||||||
long http_resp;
|
|
||||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_resp);
|
|
||||||
if (http_resp == HTTP_OK) {
|
|
||||||
double cl = 0;
|
|
||||||
curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &cl);
|
|
||||||
if (cl == -1) {
|
|
||||||
/* Turns out not to be a file after all */
|
|
||||||
this_link->content_length = 0;
|
|
||||||
this_link->type = LINK_DIR;
|
|
||||||
} else {
|
|
||||||
this_link->content_length = cl;
|
|
||||||
this_link->type = LINK_FILE;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this_link->type = LINK_INVALID;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
curl_multi_remove_handle(curl_multi, curl);
|
curl_multi_remove_handle(curl_multi, curl);
|
||||||
/* clean up the handle, if we are querying the file size */
|
/* clean up the handle, if we are querying the file size */
|
||||||
if (transfer->type == FILESIZE) {
|
if (transfer->type == FILESTAT) {
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
free(transfer);
|
free(transfer);
|
||||||
}
|
}
|
||||||
@ -467,7 +452,28 @@ static void LinkTable_add(LinkTable *linktbl, Link *link)
|
|||||||
linktbl->links[linktbl->num - 1] = link;
|
linktbl->links[linktbl->num - 1] = link;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Link_get_size(Link *this_link)
|
static void link_set_stat(Link* this_link, CURL *curl)
|
||||||
|
{
|
||||||
|
long http_resp;
|
||||||
|
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_resp);
|
||||||
|
if (http_resp == HTTP_OK) {
|
||||||
|
double cl = 0;
|
||||||
|
curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &cl);
|
||||||
|
curl_easy_getinfo(curl, CURLINFO_FILETIME, &(this_link->time));
|
||||||
|
if (cl == -1) {
|
||||||
|
/* Turns out not to be a file after all */
|
||||||
|
this_link->content_length = 0;
|
||||||
|
this_link->type = LINK_DIR;
|
||||||
|
} else {
|
||||||
|
this_link->content_length = cl;
|
||||||
|
this_link->type = LINK_FILE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this_link->type = LINK_INVALID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Link_get_stat(Link *this_link)
|
||||||
{
|
{
|
||||||
#ifdef HTTPDIRFS_INFO
|
#ifdef HTTPDIRFS_INFO
|
||||||
fprintf(stderr, "Link_get_size(%s);\n", this_link->f_url);
|
fprintf(stderr, "Link_get_size(%s);\n", this_link->f_url);
|
||||||
@ -476,13 +482,14 @@ void Link_get_size(Link *this_link)
|
|||||||
if (this_link->type == LINK_FILE) {
|
if (this_link->type == LINK_FILE) {
|
||||||
CURL *curl = Link_to_curl(this_link);
|
CURL *curl = Link_to_curl(this_link);
|
||||||
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
|
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
|
||||||
|
|
||||||
TransferStruct *transfer = malloc(sizeof(TransferStruct));
|
TransferStruct *transfer = malloc(sizeof(TransferStruct));
|
||||||
if (!transfer) {
|
if (!transfer) {
|
||||||
fprintf(stderr, "Link_get_size(): malloc failed!\n");
|
fprintf(stderr, "Link_get_size(): malloc failed!\n");
|
||||||
}
|
}
|
||||||
transfer->link = this_link;
|
transfer->link = this_link;
|
||||||
transfer->type = FILESIZE;
|
transfer->type = FILESTAT;
|
||||||
curl_easy_setopt(curl, CURLOPT_PRIVATE, transfer);
|
curl_easy_setopt(curl, CURLOPT_PRIVATE, transfer);
|
||||||
|
|
||||||
nonblocking_transfer(curl);
|
nonblocking_transfer(curl);
|
||||||
@ -500,7 +507,7 @@ void LinkTable_fill(LinkTable *linktbl)
|
|||||||
strncpy(this_link->f_url, url, URL_LEN_MAX);
|
strncpy(this_link->f_url, url, URL_LEN_MAX);
|
||||||
free(url);
|
free(url);
|
||||||
if (this_link->type == LINK_FILE && !(this_link->content_length)) {
|
if (this_link->type == LINK_FILE && !(this_link->content_length)) {
|
||||||
Link_get_size(this_link);
|
Link_get_stat(this_link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user