1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-05 10:39:27 +02:00

add a function to check if a given path is in the blob-directory

This commit is contained in:
B. Petersen 2018-10-12 01:02:26 +02:00
parent 6072d73b08
commit d7cd9c0b1e
2 changed files with 17 additions and 2 deletions

View file

@ -1429,6 +1429,21 @@ void dc_make_rel_path(dc_context_t* context, char** path)
}
/**
* Check if a path describes a file in the blob directory.
* The path can be give absolute or relative (starting with `$BLOBDIR`).
* The function does not check if the file really exists.
*/
int dc_is_in_blobdir(dc_context_t* context, const char* path)
{
if ((strncmp(path, context->blobdir, strlen(context->blobdir))==0)
|| (strncmp(path, "$BLOBDIR", 8)==0)) {
return 1;
}
return 0;
}
/**
* Copy a file to the blob directory, if needed.
*
@ -1447,8 +1462,7 @@ int dc_make_rel_and_copy(dc_context_t* context, char** path)
goto cleanup;
}
if ((strncmp(*path, context->blobdir, strlen(context->blobdir))==0)
|| (strncmp(*path, "$BLOBDIR", 8)==0)) {
if (dc_is_in_blobdir(context, *path)) {
dc_make_rel_path(context, path);
success = 1; // file is already in blobdir
goto cleanup;

View file

@ -110,6 +110,7 @@ int dc_create_folder (dc_context_t*, const char* pathNfilename);
int dc_write_file (dc_context_t*, const char* pathNfilename, const void* buf, size_t buf_bytes);
int dc_read_file (dc_context_t*, const char* pathNfilename, void** buf, size_t* buf_bytes);
char* dc_get_fine_pathNfilename (dc_context_t*, const char* pathNfolder, const char* desired_name);
int dc_is_in_blobdir (dc_context_t*, const char* path);
void dc_make_rel_path (dc_context_t*, char** pathNfilename);
int dc_make_rel_and_copy (dc_context_t*, char** pathNfilename);