From 9102a1b4c74db7b6ea9ed8e58f545b1e2b8edd74 Mon Sep 17 00:00:00 2001 From: hankertrix <91734413+hankertrix@users.noreply.github.com> Date: Mon, 23 Dec 2024 02:17:31 +0800 Subject: [PATCH] Fix: Handle the case when the archive has an empty file name Also fixed the types for the get_current_directory function and the yazi_is_loading function. --- init.lua | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/init.lua b/init.lua index aeac6b5..c633ad1 100644 --- a/init.lua +++ b/init.lua @@ -701,8 +701,7 @@ local get_config = ya.sync(function(state) end) -- Function to get the current working directory ----@param _ any ----@return string current_working_directory The current working directory +---@type fun(_): string Returns the current working directory local get_current_directory = ya.sync( function(_) return tostring(cx.active.current.cwd) end ) @@ -793,8 +792,7 @@ local get_paths_of_selected_items = ya.sync(function(_, quote) end) -- Function to get if Yazi is loading ----@param _ any ----@return boolean is_loading Whether Yazi is loading +---@type fun(_): boolean Returns whether Yazi is loading local yazi_is_loading = ya.sync( function(_) return cx.active.current.stage.is_loading end ) @@ -1549,6 +1547,22 @@ local function move_extracted_items_to_archive_parent_directory( ) end + -- Get the file name of the archive without the extension + local archive_file_name = archive_url:stem() + + -- If the archive file name is nil, + -- then return the move successful variable, + -- the error message, and the extracted item path + if not archive_file_name then + return clean_up_temporary_directory( + temporary_directory_url, + "dir_all", + move_successful, + "Archive's file name is empty", + extracted_items_path + ) + end + -- Get the first extracted item local first_extracted_item = table.unpack(extracted_items) @@ -1563,7 +1577,7 @@ local function move_extracted_items_to_archive_parent_directory( -- Initialise the target directory url to move the extracted items to, -- which is the parent directory of the archive -- joined with the file name of the archive without the extension - local target_url = parent_directory_url:join(archive_url:stem()) + local target_url = parent_directory_url:join(archive_file_name) -- If there is only one item in the archive if #extracted_items == 1 then