From 70337eb77f53cbff0b7f54f403d5b2b0a9430935 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Sun, 25 Aug 2024 20:51:27 -0700 Subject: [PATCH] fix: gracefully handle trashing file that does not exist --- lua/oil/adapters/trash/freedesktop.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lua/oil/adapters/trash/freedesktop.lua b/lua/oil/adapters/trash/freedesktop.lua index 24a6e683..c6221ab1 100644 --- a/lua/oil/adapters/trash/freedesktop.lua +++ b/lua/oil/adapters/trash/freedesktop.lua @@ -75,8 +75,13 @@ end ---@param path string ---@return string local function get_write_trash_dir(path) - local dev = uv.fs_lstat(path).dev + local lstat = uv.fs_lstat(path) local home_trash = get_home_trash_dir() + if not lstat then + -- If the source file doesn't exist default to home trash dir + return home_trash + end + local dev = lstat.dev if uv.fs_lstat(home_trash).dev == dev then return home_trash end