1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

advio: check if file is locally accessible

This commit is contained in:
Steffen Vogel 2017-08-05 21:02:36 +02:00
parent c5fc72dd78
commit 57ecb76586
2 changed files with 11 additions and 3 deletions

View file

@ -61,6 +61,9 @@ typedef struct advio AFILE;
#define auri(af) ((af)->uri)
#define ahash(af) ((af)->hash)
/** Check if a URI is pointing to a local file. */
int aislocal(const char *uri);
AFILE *afopen(const char *url, const char *mode);
int afclose(AFILE *file);
@ -72,7 +75,6 @@ int afseek(AFILE *file, long offset, int origin);
void arewind(AFILE *file);
/** Download contens from remote file
*
*
* @param resume Do a partial download and append to the local file
*/

View file

@ -169,6 +169,11 @@ static int advio_xferinfo(void *p, curl_off_t dl_total_bytes, curl_off_t dl_byte
return 0;
}
int aislocal(const char *uri)
{
return access(uri, F_OK) != -1;
}
AFILE * afopen(const char *uri, const char *mode)
{
int ret;
@ -184,7 +189,7 @@ AFILE * afopen(const char *uri, const char *mode)
if (!af->uri)
goto out2;
}
else {
else { /* Open local file by prepending file:// schema. */
if (strlen(uri) <= 1)
return NULL;
@ -416,6 +421,7 @@ int adownload(AFILE *af, int resume)
case CURLE_FILE_COULDNT_READ_FILE:
case CURLE_TFTP_NOTFOUND:
case CURLE_REMOTE_FILE_NOT_FOUND:
info("File does not exist.");
goto notexist;
/* If libcurl does not know the protocol, we will try it with the stdio */
@ -425,7 +431,7 @@ int adownload(AFILE *af, int resume)
return -1;
default:
error("ADVIO: Failed to download file: %s: %s", af->uri, curl_easy_strerror(res));
error("Failed to download file: %s: %s", af->uri, curl_easy_strerror(res));
return -1;
}