Skip to content

Commit

Permalink
Merge pull request #1131 from cozy-labs/abca-bug
Browse files Browse the repository at this point in the history
Test & fix : a -> c & b -> a bug
  • Loading branch information
sebn authored Aug 16, 2018
2 parents fad788a + 23b348a commit e1610ff
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 6 deletions.
6 changes: 3 additions & 3 deletions core/local/analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,13 @@ const finalSorter = (a /*: LocalChange */, b /*: LocalChange */) => {
if (localChange.isChildAdd(b, a)) return 1
if (localChange.isChildDelete(a, b)) return 1

if (localChange.delPath(a) === localChange.addPath(b)) return -1
if (localChange.delPath(b) === localChange.addPath(a)) return 1

// otherwise, order by add path
if (localChange.lower(localChange.addPath(a), localChange.addPath(b))) return -1
if (localChange.lower(localChange.addPath(b), localChange.addPath(a))) return 1

if (localChange.delPath(a) === localChange.addPath(b)) return -1
if (localChange.delPath(b) === localChange.addPath(a)) return 1

// if there isnt 2 add paths, sort by del path
if (localChange.lower(localChange.delPath(b), localChange.delPath(a))) return -1

Expand Down
6 changes: 3 additions & 3 deletions core/remote/change.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ const sorter = (a, b) => {
if (isChildAdd(b, a)) return 1
if (isChildDelete(a, b)) return 1

if (delPath(a) === addPath(b)) return -1
if (delPath(b) === addPath(a)) return 1

// otherwise, order by add path
if (lower(addPath(a), addPath(b))) return -1
if (lower(addPath(b), addPath(a))) return 1

if (delPath(a) === addPath(b)) return -1
if (delPath(b) === addPath(a)) return 1

// if there isnt 2 add paths, sort by del path
if (lower(delPath(b), delPath(a))) return -1

Expand Down
33 changes: 33 additions & 0 deletions test/scenarios/move_files_a_to_c_and_b_to_a/local/darwin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[
{
"breakpoints": [0, 2]
},
{
"type": "unlink",
"path": "a"
},
{
"type": "add",
"path": "c",
"stats": {
"ino": 1,
"size": 8,
"mtime": "2018-07-25T07:15:22.296Z",
"ctime": "2018-07-25T07:15:24.442Z"
}
},
{
"type": "unlink",
"path": "b"
},
{
"type": "add",
"path": "a",
"stats": {
"ino": 2,
"size": 8,
"mtime": "2018-07-25T07:15:22.301Z",
"ctime": "2018-07-25T07:15:25.949Z"
}
}
]
27 changes: 27 additions & 0 deletions test/scenarios/move_files_a_to_c_and_b_to_a/scenario.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* @flow */

/*:: import type { Scenario } from '..' */

module.exports = ({
init: [
{ino: 1, path: 'a'},
{ino: 2, path: 'b'}
],
actions: [
{type: 'mv', src: 'a', dst: 'c'},
{type: 'wait', ms: 1500},
{type: 'mv', src: 'b', dst: 'a'}
],
expected: {
prepCalls: [
// FIXME: a -> c should be first
{method: 'moveFileAsync', src: 'a', dst: 'c'},
{method: 'moveFileAsync', src: 'b', dst: 'a'}
],
tree: [
'a',
'c'
],
remoteTrash: []
}
} /*: Scenario */)

0 comments on commit e1610ff

Please sign in to comment.