Skip to content
Open
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
27 changes: 27 additions & 0 deletions src/cio_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static int cio_scan_stream_files(struct cio_ctx *ctx, struct cio_stream *st,
char *path;
DIR *dir;
struct dirent *ent;
char *entpath;

len = strlen(ctx->root_path) + strlen(st->name) + 2;
path = malloc(len);
Expand Down Expand Up @@ -100,6 +101,32 @@ static int cio_scan_stream_files(struct cio_ctx *ctx, struct cio_stream *st,

/* register every directory as a stream */
cio_chunk_open(ctx, st, ent->d_name, ctx->flags, 0, &err);

if (err == CIO_CORRUPTED) {
cio_log_debug(ctx, "[cio scan] Found corrupted chunk %s", ent->d_name);
len = strlen(path) + strlen(ent->d_name) + 2;
entpath = malloc(len);
if (!entpath) {
cio_errno();
cio_log_error(ctx, "[cio scan] Failed to delete corrupted chunk (failed to allocate path)");
continue;
}
ret = snprintf(entpath, len, "%s/%s", path, ent->d_name);
if (ret == -1) {
cio_errno();
free(entpath);
cio_log_error(ctx, "[cio scan] Failed to delete corrupted chunk (failed to construct path)");
continue;
}
ret = unlink(entpath);
if (ret == -1) {
cio_errno();
free(entpath);
cio_log_error(ctx, "[cio scan] Failed to delete corrupted chunk (failed to delete)");
continue;
}
free(entpath);
}
}

closedir(dir);
Expand Down