Skip to content

Commit a00d66d

Browse files
committed
Update: Report on readdir() errors #6610
1 parent 1a7a155 commit a00d66d

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/csync/csync_update.cpp

+25-1
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
641641
csync_file_stat_t *previous_fs = NULL;
642642
int read_from_db = 0;
643643
int rc = 0;
644+
int last_errno = 0;
644645

645646
bool do_read_from_db = (ctx->current == REMOTE_REPLICA && ctx->remote.read_from_db);
646647
const char *db_uri = uri;
@@ -712,7 +713,30 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
712713
goto error;
713714
}
714715

715-
while ((dirent = csync_vio_readdir(ctx, dh))) {
716+
while (true) {
717+
errno = 0;
718+
dirent = csync_vio_readdir(ctx, dh);
719+
if (!dirent) {
720+
// Normal case: End of items in directory
721+
if (errno == 0)
722+
break;
723+
724+
// Note: Windows vio converts any error into EACCES
725+
qCWarning(lcUpdate, "readdir failed for file in %s - errno %d", uri, errno);
726+
727+
// If we get an error during readdir, maybe that's a single unreadable
728+
// item that we can skip? It's unclear whether that can happen.
729+
// We definitely don't want to get stuck in an infinite loop here,
730+
// so stop if we get the same errno twice in a row.
731+
if (errno == last_errno) {
732+
qCWarning(lcUpdate, "Second failure, giving up on directory");
733+
goto error;
734+
}
735+
last_errno = errno;
736+
continue;
737+
}
738+
last_errno = 0;
739+
716740
/* Conversion error */
717741
if (dirent->path.isEmpty() && !dirent->original_path.isEmpty()) {
718742
ctx->status_code = CSYNC_STATUS_INVALID_CHARACTERS;

0 commit comments

Comments
 (0)