File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -196,14 +196,16 @@ module.exports = class CacheFS {
196
196
parent . delete ( basename ) ;
197
197
}
198
198
rename ( oldFilepath , newFilepath ) {
199
- // grab reference
199
+ let basename = path . basename ( newFilepath ) ;
200
+ // Note: do both lookups before making any changes
201
+ // so if lookup throws, we don't lose data (issue #23)
202
+ // grab references
200
203
let entry = this . _lookup ( oldFilepath ) ;
201
- // remove from parent directory
202
- this . unlink ( oldFilepath )
204
+ let destDir = this . _lookup ( path . dirname ( newFilepath ) ) ;
203
205
// insert into new parent directory
204
- let dir = this . _lookup ( path . dirname ( newFilepath ) ) ;
205
- let basename = path . basename ( newFilepath ) ;
206
- dir . set ( basename , entry ) ;
206
+ destDir . set ( basename , entry ) ;
207
+ // remove from old parent directory
208
+ this . unlink ( oldFilepath )
207
209
}
208
210
stat ( filepath ) {
209
211
return this . _lookup ( filepath ) . get ( STAT ) ;
You can’t perform that action at this time.
0 commit comments