fix: data loss bug when move + delete (#162)
This commit is contained in:
parent
2fde9d84fc
commit
f86d49446a
2 changed files with 21 additions and 8 deletions
|
|
@ -191,7 +191,7 @@ M.enforce_action_order = function(actions)
|
||||||
local function get_deps(action)
|
local function get_deps(action)
|
||||||
local ret = {}
|
local ret = {}
|
||||||
if action.type == "delete" then
|
if action.type == "delete" then
|
||||||
return ret
|
src_trie:accum_children_of(action.url, ret)
|
||||||
elseif action.type == "create" then
|
elseif action.type == "create" then
|
||||||
-- Finish operating on parents first
|
-- Finish operating on parents first
|
||||||
-- e.g. NEW /a BEFORE NEW /a/b
|
-- e.g. NEW /a BEFORE NEW /a/b
|
||||||
|
|
@ -289,7 +289,7 @@ M.enforce_action_order = function(actions)
|
||||||
-- We've detected a move cycle (e.g. MOVE /a -> /b + MOVE /b -> /a)
|
-- We've detected a move cycle (e.g. MOVE /a -> /b + MOVE /b -> /a)
|
||||||
-- Split one of the moves and retry
|
-- Split one of the moves and retry
|
||||||
local intermediate_url =
|
local intermediate_url =
|
||||||
string.format("%s__oil_tmp_%05d", loop_action.src_url, math.random(999999))
|
string.format("%s__oil_tmp_%05d", loop_action.src_url, math.random(999999))
|
||||||
local move_1 = {
|
local move_1 = {
|
||||||
type = "move",
|
type = "move",
|
||||||
entry_type = loop_action.entry_type,
|
entry_type = loop_action.entry_type,
|
||||||
|
|
|
||||||
|
|
@ -195,7 +195,7 @@ a.describe("mutator", function()
|
||||||
})
|
})
|
||||||
local diffs = parser.parse(bufnr)
|
local diffs = parser.parse(bufnr)
|
||||||
assert.are.same({
|
assert.are.same({
|
||||||
{ type = "new", id = file[FIELD_ID], name = "b.txt", entry_type = "file" },
|
{ type = "new", id = file[FIELD_ID], name = "b.txt", entry_type = "file" },
|
||||||
{ type = "delete", id = file[FIELD_ID], name = "a.txt" },
|
{ type = "delete", id = file[FIELD_ID], name = "a.txt" },
|
||||||
}, diffs)
|
}, diffs)
|
||||||
end)
|
end)
|
||||||
|
|
@ -314,7 +314,7 @@ a.describe("mutator", function()
|
||||||
local bufnr = vim.api.nvim_get_current_buf()
|
local bufnr = vim.api.nvim_get_current_buf()
|
||||||
local diffs = {
|
local diffs = {
|
||||||
{ type = "delete", name = "a.txt", id = file[FIELD_ID] },
|
{ type = "delete", name = "a.txt", id = file[FIELD_ID] },
|
||||||
{ type = "new", name = "b.txt", entry_type = "file", id = file[FIELD_ID] },
|
{ type = "new", name = "b.txt", entry_type = "file", id = file[FIELD_ID] },
|
||||||
}
|
}
|
||||||
local actions = mutator.create_actions_from_diffs({
|
local actions = mutator.create_actions_from_diffs({
|
||||||
[bufnr] = diffs,
|
[bufnr] = diffs,
|
||||||
|
|
@ -335,8 +335,8 @@ a.describe("mutator", function()
|
||||||
local bufnr = vim.api.nvim_get_current_buf()
|
local bufnr = vim.api.nvim_get_current_buf()
|
||||||
local diffs = {
|
local diffs = {
|
||||||
{ type = "delete", name = "a.txt", id = file[FIELD_ID] },
|
{ type = "delete", name = "a.txt", id = file[FIELD_ID] },
|
||||||
{ type = "new", name = "b.txt", entry_type = "file", id = file[FIELD_ID] },
|
{ type = "new", name = "b.txt", entry_type = "file", id = file[FIELD_ID] },
|
||||||
{ type = "new", name = "a.txt", entry_type = "file" },
|
{ type = "new", name = "a.txt", entry_type = "file" },
|
||||||
}
|
}
|
||||||
local actions = mutator.create_actions_from_diffs({
|
local actions = mutator.create_actions_from_diffs({
|
||||||
[bufnr] = diffs,
|
[bufnr] = diffs,
|
||||||
|
|
@ -363,9 +363,9 @@ a.describe("mutator", function()
|
||||||
local bufnr = vim.api.nvim_get_current_buf()
|
local bufnr = vim.api.nvim_get_current_buf()
|
||||||
local diffs = {
|
local diffs = {
|
||||||
{ type = "delete", name = "a.txt", id = afile[FIELD_ID] },
|
{ type = "delete", name = "a.txt", id = afile[FIELD_ID] },
|
||||||
{ type = "new", name = "b.txt", entry_type = "file", id = afile[FIELD_ID] },
|
{ type = "new", name = "b.txt", entry_type = "file", id = afile[FIELD_ID] },
|
||||||
{ type = "delete", name = "b.txt", id = bfile[FIELD_ID] },
|
{ type = "delete", name = "b.txt", id = bfile[FIELD_ID] },
|
||||||
{ type = "new", name = "a.txt", entry_type = "file", id = bfile[FIELD_ID] },
|
{ type = "new", name = "a.txt", entry_type = "file", id = bfile[FIELD_ID] },
|
||||||
}
|
}
|
||||||
math.randomseed(2983982)
|
math.randomseed(2983982)
|
||||||
local actions = mutator.create_actions_from_diffs({
|
local actions = mutator.create_actions_from_diffs({
|
||||||
|
|
@ -409,6 +409,19 @@ a.describe("mutator", function()
|
||||||
assert.are.same({ create, move }, ordered_actions)
|
assert.are.same({ create, move }, ordered_actions)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("Moves file out of parent before deleting parent", function()
|
||||||
|
local move = {
|
||||||
|
type = "move",
|
||||||
|
src_url = "oil-test:///a/b.txt",
|
||||||
|
dest_url = "oil-test:///b.txt",
|
||||||
|
entry_type = "file",
|
||||||
|
}
|
||||||
|
local delete = { type = "delete", url = "oil-test:///a", entry_type = "directory" }
|
||||||
|
local actions = { delete, move }
|
||||||
|
local ordered_actions = mutator.enforce_action_order(actions)
|
||||||
|
assert.are.same({ move, delete }, ordered_actions)
|
||||||
|
end)
|
||||||
|
|
||||||
it("Handles parent child move ordering", function()
|
it("Handles parent child move ordering", function()
|
||||||
-- move parent into a child and child OUT of parent
|
-- move parent into a child and child OUT of parent
|
||||||
-- MOVE /a/b -> /b
|
-- MOVE /a/b -> /b
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue