@@ -239,7 +239,7 @@ static bpc_attribCache_dir *bpc_attribCache_loadPath(bpc_attribCache_info *ac, b
239239 for ( i = 0 ; i < ac -> bkupMergeCnt ; i ++ ) {
240240 bpc_attrib_dir dir ;
241241 ssize_t entrySize ;
242- char * entries , * fileName ;
242+ char * entries , * entry ;
243243
244244 bpc_strBuf_snprintf (topDir , 0 , "%s/pc/%s/%d" , BPC_TopDir .s , ac -> hostName -> s , ac -> bkupMergeList [i ].num );
245245 bpc_strBuf_snprintf (fullAttribPath , 0 , "%s/%s" , topDir -> s , attribPath -> s );
@@ -275,27 +275,30 @@ static bpc_attribCache_dir *bpc_attribCache_loadPath(bpc_attribCache_info *ac, b
275275 }
276276 bpc_logErrf ("bpc_attribCache_loadPath: bpc_attrib_dirRead(%s/%s) returned %d\n" , topDir -> s , attribPath -> s , status );
277277 }
278+ if ( bpc_attrib_dirNeedRewrite (& dir ) ) {
279+ attr -> dirty = 1 ;
280+ }
278281 entrySize = bpc_attrib_getEntries (& dir , NULL , 0 );
279282 if ( (entries = malloc (entrySize + 1 )) && bpc_attrib_getEntries (& dir , entries , entrySize ) == entrySize ) {
280- for ( fileName = entries ; fileName < entries + entrySize ; fileName += strlen (fileName ) + 1 ) {
281- bpc_attrib_file * file = bpc_attrib_fileGet (& dir , fileName , 0 );
283+ for ( entry = entries ; entry < entries + entrySize ; entry += strlen (entry ) + 1 ) {
284+ bpc_attrib_file * file = bpc_attrib_fileGet (& dir , entry , 0 );
282285 if ( !file ) continue ;
283286 if ( file -> type == BPC_FTYPE_DELETED ) {
284- bpc_attrib_fileDeleteName (& attr -> dir , fileName );
287+ bpc_attrib_fileDeleteName (& attr -> dir , entry );
285288 } else {
286289 bpc_attrib_file * fileDest ;
287290
288- if ( !(fileDest = bpc_attrib_fileGet (& attr -> dir , fileName , 1 )) ) {
291+ if ( !(fileDest = bpc_attrib_fileGet (& attr -> dir , entry , 1 )) ) {
289292 bpc_strBuf_free (attribPath );
290293 bpc_strBuf_free (topDir );
291294 bpc_strBuf_free (fullAttribPath );
292295 return NULL ;
293296 }
294- if ( fileDest -> key .key == fileName ) {
297+ if ( fileDest -> key .key == entry ) {
295298 /*
296299 * new entry - initialize
297300 */
298- bpc_attrib_fileInit (fileDest , fileName , 0 );
301+ bpc_attrib_fileInit (fileDest , entry , 0 );
299302 }
300303 bpc_attrib_fileCopy (fileDest , file );
301304 fileDest -> backupNum = ac -> bkupMergeList [i ].num ;
@@ -323,11 +326,17 @@ static bpc_attribCache_dir *bpc_attribCache_loadPath(bpc_attribCache_info *ac, b
323326 if ( (status = bpc_attrib_dirRead (& attr -> dir , ac -> backupTopDir -> s , attribPath -> s , ac -> backupNum )) ) {
324327 bpc_logErrf ("bpc_attribCache_loadPath: bpc_attrib_dirRead(%s, %s) returned %d\n" , ac -> backupTopDir -> s , attribPath -> s , status );
325328 }
329+ if ( bpc_attrib_dirNeedRewrite (& attr -> dir ) ) {
330+ attr -> dirty = 1 ;
331+ }
326332 /*
327333 * remove any extraneous BPC_FTYPE_DELETED file types
328334 */
329335 bpc_hashtable_iterate (& attr -> dir .filesHT , (void * )bpc_attribCache_removeDeletedEntries , attr );
330336 }
337+ if ( attr -> dirty ) {
338+ if ( BPC_LogLevel >= 8 ) bpc_logMsgf ("bpc_attribCache_loadPath: will rewrite path = %s -> dir = %s, fileName = %s, attribPath = %s\n" , path , dirStr -> s , fileName , attribPath -> s );
339+ }
331340 if ( bpc_hashtable_entryCount (& ac -> attrHT ) > BPC_ATTRIBCACHE_DIR_COUNT_MAX ) {
332341 bpc_attribCache_flush (ac , 0 , NULL );
333342 }
@@ -382,7 +391,7 @@ static bpc_attribCache_dir *bpc_attribCache_loadInode(bpc_attribCache_info *ac,
382391 for ( i = 0 ; i < ac -> bkupMergeCnt ; i ++ ) {
383392 bpc_attrib_dir dir ;
384393 ssize_t entrySize ;
385- char * entries , * fileName ;
394+ char * entries , * entry ;
386395
387396 bpc_strBuf_snprintf (inodeDir , 0 , "%s/pc/%s/%d/%s" , BPC_TopDir .s , ac -> hostName -> s , ac -> bkupMergeList [i ].num , attribDir -> s );
388397 bpc_strBuf_snprintf (fullAttribPath , 0 , "%s/%s" , inodeDir -> s , attribFile -> s );
@@ -400,29 +409,32 @@ static bpc_attribCache_dir *bpc_attribCache_loadInode(bpc_attribCache_info *ac,
400409 }
401410 bpc_logErrf ("bpc_attribCache_loadInode: bpc_attrib_dirRead(%s/%s) returned %d\n" , inodeDir -> s , attribFile -> s , status );
402411 }
412+ if ( bpc_attrib_dirNeedRewrite (& dir ) ) {
413+ attr -> dirty = 1 ;
414+ }
403415 entrySize = bpc_attrib_getEntries (& dir , NULL , 0 );
404416 if ( (entries = malloc (entrySize + 1 )) && bpc_attrib_getEntries (& dir , entries , entrySize ) == entrySize ) {
405- for ( fileName = entries ; fileName < entries + entrySize ; fileName += strlen (fileName ) + 1 ) {
406- bpc_attrib_file * file = bpc_attrib_fileGet (& dir , fileName , 0 );
417+ for ( entry = entries ; entry < entries + entrySize ; entry += strlen (entry ) + 1 ) {
418+ bpc_attrib_file * file = bpc_attrib_fileGet (& dir , entry , 0 );
407419 if ( !file ) continue ;
408420 if ( file -> type == BPC_FTYPE_DELETED ) {
409- bpc_attrib_fileDeleteName (& attr -> dir , fileName );
421+ bpc_attrib_fileDeleteName (& attr -> dir , entry );
410422 } else {
411423 bpc_attrib_file * fileDest ;
412424
413- if ( !(fileDest = bpc_attrib_fileGet (& attr -> dir , fileName , 1 )) ) {
425+ if ( !(fileDest = bpc_attrib_fileGet (& attr -> dir , entry , 1 )) ) {
414426 bpc_strBuf_free (attribPath );
415427 bpc_strBuf_free (attribDir );
416428 bpc_strBuf_free (attribFile );
417429 bpc_strBuf_free (inodeDir );
418430 bpc_strBuf_free (fullAttribPath );
419431 return NULL ;
420432 }
421- if ( fileDest -> key .key == fileName ) {
433+ if ( fileDest -> key .key == entry ) {
422434 /*
423435 * new entry - initialize
424436 */
425- bpc_attrib_fileInit (fileDest , fileName , 0 );
437+ bpc_attrib_fileInit (fileDest , entry , 0 );
426438 }
427439 bpc_attrib_fileCopy (fileDest , file );
428440 }
@@ -451,6 +463,12 @@ static bpc_attribCache_dir *bpc_attribCache_loadInode(bpc_attribCache_info *ac,
451463 if ( (status = bpc_attrib_dirRead (& attr -> dir , inodeDir -> s , attribFile -> s , ac -> backupNum )) ) {
452464 bpc_logErrf ("bpc_attribCache_loadInode: bpc_attrib_dirRead(%s/%s) returned %d\n" , inodeDir -> s , attribFile -> s , status );
453465 }
466+ if ( bpc_attrib_dirNeedRewrite (& attr -> dir ) ) {
467+ attr -> dirty = 1 ;
468+ }
469+ }
470+ if ( attr -> dirty ) {
471+ if ( BPC_LogLevel >= 8 ) bpc_logMsgf ("bpc_attribCache_loadInode: will rewrite path = %s -> dir = %s, fileName = %s\n" , attribPath , attribDir , attribFile );
454472 }
455473 if ( bpc_hashtable_entryCount (& ac -> inodeHT ) > BPC_ATTRIBCACHE_DIR_COUNT_MAX ) {
456474 bpc_attribCache_flush (ac , 0 , NULL );
0 commit comments