Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
taratatach committed Oct 16, 2024
1 parent f6cd44c commit 12ad2b4
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 160 deletions.
36 changes: 22 additions & 14 deletions core/local/chokidar/analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,26 @@ class LocalChangeMap {
if (change) return callback(change)
}

put(c /*: LocalChange */, updated /*: ?boolean */) {
if (updated) {
for (const [k, v] of this.changesByPath) {
if (v == c) {
this.changesByPath.delete(k)
break
}
put(c /*: LocalChange */, toReplace /*: ?LocalChange */) {
if (toReplace) {
this.changesByPath.delete(toReplace.path.normalize())
this.changesByPath.set(c.path.normalize(), c)

if (typeof toReplace.ino === 'number') {
this.changesByInode.set(toReplace.ino, c)
} else {
const index = this.changes.indexOf(toReplace)
this.changes.splice(index, 1, c)
}
} else {
this.changesByPath.set(c.path.normalize(), c)

if (typeof c.ino === 'number') {
this.changesByInode.set(c.ino, c)
} else {
this.changes.push(c)
}
}
this.changesByPath.set(c.path.normalize(), c)
if (typeof c.ino === 'number') this.changesByInode.set(c.ino, c)
else this.changes.push(c)
}

flush() /*: LocalChange[] */ {
Expand Down Expand Up @@ -176,9 +184,9 @@ function analyseEvents(
const result = analyseEvent(e, changesFound)
if (result == null) continue // No change was found. Skip event.

// A new change was found or updated
const [change, updated] = result
changesFound.put(change, updated)
// A new change was found or one that should be replaced
const [change, toReplace] = result
changesFound.put(change, toReplace)
} catch (err) {
const sentry = err.name === 'InvalidLocalMoveEvent'
log.error('Invalid local move event', { err, path: e.path, sentry })
Expand All @@ -196,7 +204,7 @@ function analyseEvents(
function analyseEvent(
e /*: LocalEvent */,
previousChanges /*: LocalChangeMap */
) /*: ?[LocalChange, boolean] */ {
) /*: ?[LocalChange, ?LocalChange] */ {
const sameInodeChange = previousChanges.findByInode(getInode(e))

switch (e.type) {
Expand Down
Loading

0 comments on commit 12ad2b4

Please sign in to comment.