Only mark a folder as modified if files within it are modified.

This commit is contained in:
Olivier Goffart 2013-03-11 19:55:07 +01:00
parent 6a5ad6e81e
commit b99677f985
3 changed files with 31 additions and 2 deletions

View file

@ -154,6 +154,8 @@ int csync_create(CSYNC **csync, const char *local, const char *remote) {
return -1;
}
ctx->current_fs = NULL;
*csync = ctx;
return 0;
}

View file

@ -79,6 +79,9 @@ enum csync_replica_e {
REMOTE_REPLICA
};
typedef struct csync_file_stat_s csync_file_stat_t;
/**
* @brief csync public structure
*/
@ -151,6 +154,10 @@ struct csync_s {
/* replica we want to work on */
enum csync_replica_e replica;
/* Used in the update phase so changes in the sub directories can be notified to
parent directories */
csync_file_stat_t *current_fs;
/* error code of the last operation */
enum csync_error_codes_e error_code;
char *error_string;
@ -174,6 +181,7 @@ struct csync_file_stat_s {
mode_t mode; /* u32 */
int nlink; /* u32 */
int type; /* u32 */
int child_modified;/*bool*/
char *destpath; /* for renames */
const char *md5;
@ -189,8 +197,6 @@ __attribute__ ((packed))
#endif
;
typedef struct csync_file_stat_s csync_file_stat_t;
/*
* context for the treewalk function
*/

View file

@ -91,6 +91,7 @@ static int _csync_detect_update(CSYNC *ctx, const char *file,
/* Set instruction by default to none */
st->instruction = CSYNC_INSTRUCTION_NONE;
st->md5 = NULL;
st->child_modified = 0;
/* check hardlink count */
if (type == CSYNC_FTW_TYPE_FILE && fs->nlink > 1) {
@ -157,6 +158,13 @@ static int _csync_detect_update(CSYNC *ctx, const char *file,
}
out:
if (st->instruction != CSYNC_INSTRUCTION_NONE && st->instruction != CSYNC_INSTRUCTION_IGNORE
&& type != CSYNC_FTW_TYPE_DIR) {
st->child_modified = 1;
}
ctx->current_fs = st;
if( tmp) SAFE_FREE(tmp->md5);
SAFE_FREE(tmp);
st->inode = fs->inode;
@ -296,6 +304,7 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
csync_vio_handle_t *dh = NULL;
csync_vio_file_stat_t *dirent = NULL;
csync_vio_file_stat_t *fs = NULL;
csync_file_stat_t *previous_fs = NULL;
int read_from_db = 0;
int rc = 0;
int res = 0;
@ -430,9 +439,14 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
CSYNC_LOG(CSYNC_LOG_PRIORITY_TRACE, "walk: %s", filename);
previous_fs = ctx->current_fs;
/* Call walker function for each file */
rc = fn(ctx, filename, fs, flag);
if (ctx->current_fs && previous_fs && ctx->current_fs->child_modified)
previous_fs->child_modified = ctx->current_fs->child_modified;
if( ! do_read_from_db )
csync_vio_file_stat_destroy(fs);
else
@ -440,16 +454,23 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
if (rc < 0) {
csync_vio_closedir(ctx, dh);
ctx->current_fs = previous_fs;
goto done;
}
if (flag == CSYNC_FTW_FLAG_DIR && depth) {
rc = csync_ftw(ctx, filename, fn, depth - 1);
if (rc < 0) {
ctx->current_fs = previous_fs;
csync_vio_closedir(ctx, dh);
goto done;
}
if (ctx->current_fs && !ctx->current_fs->child_modified
&& ctx->current_fs->instruction == CSYNC_INSTRUCTION_EVAL)
ctx->current_fs->instruction = CSYNC_INSTRUCTION_NONE;
}
ctx->current_fs = previous_fs;
SAFE_FREE(filename);
csync_vio_file_stat_destroy(dirent);
dirent = NULL;