Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/flb_fstore.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,33 @@ struct flb_fstore_file *flb_fstore_file_get(struct flb_fstore *fs,
* Set a file to inactive mode. Inactive means just to remove the reference
* from the list.
*/
static int chunk_is_linked_to_stream(struct flb_fstore_file *fsf)
{
struct mk_list *head;
struct cio_chunk *chunk;

if (fsf == NULL || fsf->chunk == NULL || fsf->stream == NULL) {
return FLB_FALSE;
}

mk_list_foreach(head, &fsf->stream->chunks) {
chunk = mk_list_entry(head, struct cio_chunk, _head);

if (chunk == fsf->chunk) {
return FLB_TRUE;
}
}

return FLB_FALSE;
}

int flb_fstore_file_inactive(struct flb_fstore *fs,
struct flb_fstore_file *fsf)
{
/* close the Chunk I/O reference, but don't delete the real file */
if (fsf->chunk) {
if (chunk_is_linked_to_stream(fsf) == FLB_TRUE) {
cio_chunk_close(fsf->chunk, CIO_FALSE);
fsf->chunk = NULL;
}

/* release */
Expand All @@ -239,7 +260,10 @@ int flb_fstore_file_delete(struct flb_fstore *fs,
struct flb_fstore_file *fsf)
{
/* close the Chunk I/O reference, but don't delete it the real file */
cio_chunk_close(fsf->chunk, CIO_TRUE);
if (chunk_is_linked_to_stream(fsf) == FLB_TRUE) {
cio_chunk_close(fsf->chunk, CIO_TRUE);
fsf->chunk = NULL;
}
Comment on lines +263 to +266
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Comment says “don’t delete”; code deletes. Fix the comment.

The block uses CIO_TRUE (delete real file), but the comment says “don’t delete”. Correct the comment to avoid confusion.

Apply:

-    /* close the Chunk I/O reference, but don't delete it the real file */
+    /* close the Chunk I/O reference and delete the real file */

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/flb_fstore.c around lines 263 to 266, the surrounding comment incorrectly
states “don’t delete” while the code calls cio_chunk_close(fsf->chunk, CIO_TRUE)
which deletes the underlying file; update the comment to accurately reflect that
the chunk is closed and the real file is deleted (e.g., "close chunk and delete
underlying file") so the comment matches the behavior and avoids confusion.


/* release */
mk_list_del(&fsf->_head);
Expand Down Expand Up @@ -415,6 +439,7 @@ static int map_chunks(struct flb_fstore *ctx, struct flb_fstore_stream *fs_strea
return -1;
}

fsf->stream = stream;
fsf->chunk = chunk;

/* load metadata */
Expand Down
51 changes: 51 additions & 0 deletions tests/internal/fstore.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>

#ifdef FLB_SYSTEM_WINDOWS
/* Not yet implemented! */
Expand Down Expand Up @@ -78,7 +79,57 @@ void cb_all()
flb_fstore_destroy(fs);
}

void cb_delete_after_external_close()
{
int ret;
struct stat st_data;
struct flb_fstore *fs;
struct flb_fstore_stream *st;
struct flb_fstore_file *fsf;
struct cio_chunk *chunk;

cio_utils_recursive_delete(FSF_STORE_PATH);

fs = flb_fstore_create(FSF_STORE_PATH, FLB_FSTORE_FS);
TEST_CHECK(fs != NULL);
if (!fs) {
return;
}

st = flb_fstore_stream_create(fs, "abc");
TEST_CHECK(st != NULL);
if (!st) {
flb_fstore_destroy(fs);
return;
}

fsf = flb_fstore_file_create(fs, st, "example.txt", 100);
TEST_CHECK(fsf != NULL);
if (!fsf) {
flb_fstore_destroy(fs);
return;
}

chunk = fsf->chunk;
TEST_CHECK(chunk != NULL);
if (!chunk) {
flb_fstore_destroy(fs);
return;
}

cio_chunk_close(chunk, CIO_TRUE);

ret = stat(FSF_STORE_PATH "/abc/example.txt", &st_data);
TEST_CHECK(ret == -1 && errno == ENOENT);

ret = flb_fstore_file_delete(fs, fsf);
TEST_CHECK(ret == 0);

flb_fstore_destroy(fs);
}

TEST_LIST = {
{ "all" , cb_all},
{ "delete_after_external_close", cb_delete_after_external_close},
{ NULL }
};
Loading