257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
-
+
+
-
+
+
+
-
+
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
|
** rollback all the filesystem changes.
*/
static int undoNeedRollback = 0;
/*
** Save the current content of the file zPathname so that it
** will be undoable. The name is relative to the root of the
** tree.
** tree. Any file bigger than "limit" will not be stored in
** the undo table, and cause this function to return 1.
*/
void undo_save(const char *zPathname){
int undo_save(const char *zPathname, i64 limit){
char *zFullname;
Blob content;
int existsFlag;
int isLink;
Stmt q;
int result = 0;
i64 size;
if( !undoActive ) return;
if( !undoActive ) return 0;
zFullname = mprintf("%s%s", g.zLocalRoot, zPathname);
existsFlag = file_wd_size(zFullname)>=0;
size = file_wd_size(zFullname);
existsFlag = size>=0;
isLink = file_wd_islink(zFullname);
if( limit>=0 && size>limit ){
result = 1;
}else{
db_prepare(&q,
"INSERT OR IGNORE INTO"
" undo(pathname,redoflag,existsflag,isExe,isLink,content)"
" VALUES(%Q,0,%d,%d,%d,:c)",
zPathname, existsFlag, file_wd_isexe(zFullname), isLink
);
if( existsFlag ){
if( isLink ){
blob_read_link(&content, zFullname);
}else{
blob_read_from_file(&content, zFullname);
}
db_bind_blob(&q, ":c", &content);
}
db_prepare(&q,
"INSERT OR IGNORE INTO"
" undo(pathname,redoflag,existsflag,isExe,isLink,content)"
" VALUES(%Q,0,%d,%d,%d,:c)",
zPathname, size>=0, file_wd_isexe(zFullname), isLink
);
if( existsFlag ){
if( isLink ){
blob_read_link(&content, zFullname);
}else{
blob_read_from_file(&content, zFullname);
}
db_bind_blob(&q, ":c", &content);
}
free(zFullname);
db_step(&q);
db_finalize(&q);
if( existsFlag ){
blob_reset(&content);
}
db_step(&q);
db_finalize(&q);
if( existsFlag ){
blob_reset(&content);
}
}
free(zFullname);
undoNeedRollback = 1;
return result;
}
/*
** Make the current state of stashid undoable.
*/
void undo_save_stash(int stashid){
const char *zDb = db_name("localdb");
|