Skip to content

Commit 5d9e436

Browse files
committed
fix(trash): error deleting dangling symbolic links to trash (#251)
1 parent 22ab2ce commit 5d9e436

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lua/oil/adapters/trash/freedesktop.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ end
4242
---@return string[]
4343
local function get_top_trash_dirs(path)
4444
local dirs = {}
45-
local dev = (uv.fs_stat(path) or {}).dev
45+
local dev = (uv.fs_lstat(path) or {}).dev
4646
local top_trash_dirs = vim.fs.find(".Trash", { upward = true, path = path, limit = math.huge })
4747
for _, top_trash_dir in ipairs(top_trash_dirs) do
48-
local stat = uv.fs_stat(top_trash_dir)
48+
local stat = uv.fs_lstat(top_trash_dir)
4949
if stat and not dev then
5050
dev = stat.dev
5151
end
@@ -62,7 +62,7 @@ local function get_top_trash_dirs(path)
6262
{ upward = true, path = path, limit = math.huge }
6363
)
6464
for _, top_trash_dir in ipairs(top_trash_dirs) do
65-
local stat = uv.fs_stat(top_trash_dir)
65+
local stat = uv.fs_lstat(top_trash_dir)
6666
if stat and stat.dev == dev then
6767
ensure_trash_dir(top_trash_dir)
6868
table.insert(dirs, top_trash_dir)
@@ -75,9 +75,9 @@ end
7575
---@param path string
7676
---@return string
7777
local function get_write_trash_dir(path)
78-
local dev = uv.fs_stat(path).dev
78+
local dev = uv.fs_lstat(path).dev
7979
local home_trash = get_home_trash_dir()
80-
if uv.fs_stat(home_trash).dev == dev then
80+
if uv.fs_lstat(home_trash).dev == dev then
8181
return home_trash
8282
end
8383

@@ -88,7 +88,7 @@ local function get_write_trash_dir(path)
8888

8989
local parent = vim.fn.fnamemodify(path, ":h")
9090
local next_parent = vim.fn.fnamemodify(parent, ":h")
91-
while parent ~= next_parent and uv.fs_stat(next_parent).dev == dev do
91+
while parent ~= next_parent and uv.fs_lstat(next_parent).dev == dev do
9292
parent = next_parent
9393
next_parent = vim.fn.fnamemodify(parent, ":h")
9494
end
@@ -200,7 +200,7 @@ local function read_trash_info(info_file, cb)
200200

201201
local basename = vim.fn.fnamemodify(info_file, ":t:r")
202202
trash_info.trash_file = fs.join(trash_base, "files", basename)
203-
uv.fs_stat(trash_info.trash_file, function(trash_stat_err, trash_stat)
203+
uv.fs_lstat(trash_info.trash_file, function(trash_stat_err, trash_stat)
204204
if trash_stat_err then
205205
cb(".trashinfo file points to non-existant file")
206206
else
@@ -526,7 +526,7 @@ local function create_trash_info(path, cb)
526526
local name = string.format("%s-%d.%d", basename, now, math.random(100000, 999999))
527527
local dest_path = fs.join(trash_dir, "files", name)
528528
local dest_info = fs.join(trash_dir, "info", name .. ".trashinfo")
529-
uv.fs_stat(path, function(err, stat)
529+
uv.fs_lstat(path, function(err, stat)
530530
if err then
531531
return cb(err)
532532
end

0 commit comments

Comments
 (0)