diff --git a/src/dc_tools.c b/src/dc_tools.c index 87789bf5..2181bf8c 100644 --- a/src/dc_tools.c +++ b/src/dc_tools.c @@ -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; diff --git a/src/dc_tools.h b/src/dc_tools.h index 844224c2..5d7aa6e2 100644 --- a/src/dc_tools.h +++ b/src/dc_tools.h @@ -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);