Skip to content

Commit

Permalink
fix update of content json if cached file was skipped
Browse files Browse the repository at this point in the history
fix fsCompareFile NULL position
  • Loading branch information
SciLor committed Mar 29, 2024
1 parent 2a6a2d6 commit 10a535d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/fs_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ FsFile *fsOpenFileEx(const char_t *path, char *mode)

error_t fsCompareFiles(const char_t *source_path, const char_t *target_path, size_t *diff_position)
{
size_t position = 0;
if (diff_position == NULL)
{
diff_position = &position;
}

if (!fsFileExists(source_path))
{
return ERROR_FILE_NOT_FOUND;
Expand Down
10 changes: 8 additions & 2 deletions src/handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,14 @@ void cbrCloudBodyPassthrough(void *src_ctx, HttpClientContext *cloud_ctx, const

tonie_info_t *tonieInfoLib = getTonieInfo(libraryPath, ctx->client_ctx->settings);
bool moveToLibrary = true;
bool skipMove = false;
if (tonieInfoLib->valid)
{
if (!osMemcmp(tonieInfoLib->tafHeader->sha1_hash.data, tonieInfo->tafHeader->sha1_hash.data, tonieInfoLib->tafHeader->sha1_hash.len))
{
TRACE_WARNING(">> SHA1 Hash for Audio ID %" PRIu32 ", already in library, deleting downloaded file\r\n", audioId);
fsDeleteFile(ctx->tonieInfo->contentPath);
skipMove = true;
}
else
{
Expand All @@ -185,7 +187,11 @@ void cbrCloudBodyPassthrough(void *src_ctx, HttpClientContext *cloud_ctx, const
}
if (moveToLibrary)
{
error_t error = fsMoveFile(ctx->tonieInfo->contentPath, libraryPath, false);
error_t error = NO_ERROR;
if (!skipMove)
{
error = fsMoveFile(ctx->tonieInfo->contentPath, libraryPath, false);
}
if (error == NO_ERROR)
{
char *libraryShortPath = custom_asprintf("lib://by/audioID/%" PRIu32 ".taf", audioId);
Expand All @@ -194,7 +200,7 @@ void cbrCloudBodyPassthrough(void *src_ctx, HttpClientContext *cloud_ctx, const
tonieInfo->json.source = libraryShortPath;

save_content_json(tonieInfo->contentPath, &tonieInfo->json);
TRACE_INFO(">> Successfully moved to library %s\r\n", libraryShortPath);
TRACE_INFO(">> Successfully set to library %s\r\n", libraryShortPath);
}
else
{
Expand Down

0 comments on commit 10a535d

Please sign in to comment.