@@ -157,28 +157,40 @@ impl FsStore {
157
157
// Load all the data we have into a doc
158
158
match Chunks :: load ( & self . root , id) {
159
159
Ok ( Some ( chunks) ) => {
160
+ println ! ( "hmm..." ) ;
160
161
let doc = chunks
161
162
. to_doc ( )
162
163
. map_err ( |e| Error ( ErrorKind :: LoadDocToCompact ( e) ) ) ?;
163
164
164
165
// Write the snapshot
165
166
let output_chunk_name = SavedChunkName :: new_snapshot ( doc. get_heads ( ) ) ;
166
167
let chunk = doc. save ( ) ;
167
- write_chunk ( & self . root , & paths, & chunk, output_chunk_name) ?;
168
+ println ! ( "Going to write: {:#?}" , output_chunk_name) ;
169
+ write_chunk ( & self . root , & paths, & chunk, output_chunk_name. clone ( ) ) ?;
168
170
169
171
// Remove all the old data
170
172
for incremental in chunks. incrementals . keys ( ) {
171
173
let path = paths. chunk_path ( & self . root , incremental) ;
174
+ println ! ( "Removing {:?}" , path) ;
172
175
std:: fs:: remove_file ( & path)
173
176
. map_err ( |e| Error ( ErrorKind :: DeleteChunk ( path, e) ) ) ?;
174
177
}
178
+ let just_wrote = paths. chunk_path ( & self . root , & output_chunk_name) ;
175
179
for snapshot in chunks. snapshots . keys ( ) {
176
180
let path = paths. chunk_path ( & self . root , snapshot) ;
181
+ println ! ( "Removing Snap {:?}" , path) ;
182
+
183
+ if path == just_wrote {
184
+ tracing:: error!( "Somehow trying to delete the same path we just wrote to. Not today Satan" ) ;
185
+ continue ;
186
+ }
187
+
177
188
std:: fs:: remove_file ( & path)
178
189
. map_err ( |e| Error ( ErrorKind :: DeleteChunk ( path, e) ) ) ?;
179
190
}
180
191
}
181
192
Ok ( None ) => {
193
+ println ! ( "No existing files,and compaction requested first" ) ;
182
194
let output_chunk_name = SavedChunkName {
183
195
hash : uuid:: Uuid :: new_v4 ( ) . as_bytes ( ) . to_vec ( ) ,
184
196
chunk_type : ChunkType :: Snapshot ,
@@ -187,6 +199,7 @@ impl FsStore {
187
199
write_chunk ( & self . root , & paths, full_doc, output_chunk_name) ?;
188
200
}
189
201
Err ( e) => {
202
+ println ! ( "Error loading chunks for {:?} {}" , self . root, id) ;
190
203
tracing:: error!( e=%e, "Error loading chunks" ) ;
191
204
}
192
205
}
@@ -219,6 +232,10 @@ fn write_chunk(
219
232
// Move the temporary file into a snapshot in the document data directory
220
233
// with a name based on the hash of the heads of the document
221
234
let output_path = paths. chunk_path ( root, & name) ;
235
+
236
+ tracing:: warn!( "Renaming: {:?}" , temp_save) ;
237
+ tracing:: warn!( "To: {:?}" , output_path) ;
238
+
222
239
std:: fs:: rename ( & temp_save_path, & output_path)
223
240
. map_err ( |e| Error ( ErrorKind :: RenameTempFile ( temp_save_path, output_path, e) ) ) ?;
224
241
@@ -286,13 +303,13 @@ impl DocIdPaths {
286
303
}
287
304
}
288
305
289
- #[ derive( Debug , Hash , PartialEq , Eq ) ]
306
+ #[ derive( Debug , Hash , PartialEq , Eq , Clone ) ]
290
307
enum ChunkType {
291
308
Snapshot ,
292
309
Incremental ,
293
310
}
294
311
295
- #[ derive( Debug , Hash , PartialEq , Eq ) ]
312
+ #[ derive( Debug , Hash , PartialEq , Eq , Clone ) ]
296
313
struct SavedChunkName {
297
314
hash : Vec < u8 > ,
298
315
chunk_type : ChunkType ,
@@ -355,7 +372,7 @@ impl Chunks {
355
372
fn load ( root : & Path , doc_id : & DocumentId ) -> Result < Option < Self > , Error > {
356
373
let doc_id_hash = DocIdPaths :: from ( doc_id) ;
357
374
let level2_path = doc_id_hash. level2_path ( root) ;
358
- tracing:: debug !(
375
+ tracing:: warn !(
359
376
root=%root. display( ) ,
360
377
doc_id=?doc_id,
361
378
doc_path=%level2_path. display( ) ,
@@ -439,7 +456,11 @@ impl Chunks {
439
456
for chunk in self . incrementals . values ( ) {
440
457
bytes. extend ( chunk) ;
441
458
}
442
- automerge:: Automerge :: load ( & bytes)
459
+
460
+ automerge:: Automerge :: load_with_options (
461
+ & bytes,
462
+ automerge:: LoadOptions :: new ( ) . on_partial_load ( automerge:: OnPartialLoad :: Ignore ) ,
463
+ )
443
464
}
444
465
}
445
466
0 commit comments