1010#include "fs.h"
1111#include "index.h"
1212#include "log.h"
13+ #include "xx.h"
14+
15+ /// @def XXBUFSZE
16+ /// @brief Size of the buffer used for reading files to hash.
17+ #define XXBUFSZE 65536
18+
19+ static uint8_t xxbuf [XXBUFSZE ];///< Shared buffer for reading files to hash
1320
1421/// @struct deng_state_s
1522/// @brief Search state context provided to the diff engine as user data which
@@ -58,14 +65,15 @@ static int stagepre(const char* fp, const struct fsstat_s* st, void* udata) {
5865 // attempt to match file in previous index
5966 struct inode_s * prev = indexfind (mach -> lastmap , fp , fphash );
6067
61- // lookup from previous iteration or insert new record and lookup
62- struct inode_s * curr = indexfind (mach -> thismap , fp , fphash );
63- if (curr == NULL )
64- if ((curr = indexput (mach -> thismap , fp , fphash , st )) == NULL ) return -1 ;
68+ // insert node for current index
69+ struct inode_s * curr = indexput (mach -> thismap , fp , fphash , st , 0 );
70+ if (!curr ) return -1 ;
6571
6672 if (prev != NULL ) {
67- if (prev -> st .lmod != st -> lmod || prev -> st .fsze != st -> fsze )
68- callevent (mach , DENG_FEVENT_MOD , curr );
73+ // file existed in previous index, check if modified
74+ struct xxreq_s req = {xxbuf , fp , & prev -> st , st , prev -> xx };
75+ curr -> xx = xxupdate (& req , "stage=pre,node=existing" );
76+ if (req .pxx != curr -> xx ) callevent (mach , DENG_FEVENT_MOD , curr );
6977 } else {
7078 callevent (mach , DENG_FEVENT_NEW , curr );
7179 }
@@ -86,16 +94,28 @@ static int stagepost(const char* fp, const struct fsstat_s* st, void* udata) {
8694
8795 if (mach -> ffn != NULL && mach -> ffn (fp )) return 0 ;// skip filtered files
8896
89- const uint64_t fphash = indexhash (fp );
97+ struct xxreq_s req = {xxbuf , fp , NULL , st , 0 };
98+ char * cause = NULL ;
9099
100+ const uint64_t fphash = indexhash (fp );
91101 struct inode_s * curr = indexfind (mach -> thismap , fp , fphash );
92102 if (curr != NULL ) {
93- curr -> st = * st ;// update the file info in the current index
94- return 0 ;
103+ req .pst = & curr -> st ;
104+ req .pxx = curr -> xx ;
105+ cause = "stage=post,node=existing" ;
106+ } else {
107+ cause = "stage=post,node=new" ;
95108 }
96109
97- if ((curr = indexput (mach -> thismap , fp , fphash , st )) == NULL ) return -1 ;
98- callevent (mach , DENG_FEVENT_NEW , curr );
110+ const uint64_t xx = xxupdate (& req , cause );
111+
112+ if (curr != NULL ) {
113+ curr -> xx = xx ;// update hash of existing record
114+ } else {
115+ // file was not found in previous stage, insert new record
116+ if ((curr = indexput (mach -> thismap , fp , fphash , st , xx )) == NULL ) return -1 ;
117+ callevent (mach , DENG_FEVENT_NEW , curr );
118+ }
99119
100120 return 0 ;
101121}
0 commit comments