From 1be1c7fb0bfc3a275cf61f4a03317e1d2efbb466 Mon Sep 17 00:00:00 2001 From: George Sokianos Date: Mon, 19 Feb 2024 00:56:45 +0000 Subject: [PATCH] More fixes with the relative paths --- README_Amiga.md | 6 +++--- data/core/common.lua | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/README_Amiga.md b/README_Amiga.md index a6ea3062..19db0113 100644 --- a/README_Amiga.md +++ b/README_Amiga.md @@ -237,11 +237,11 @@ https://git.walkero.gr/walkero/lite-xl/issues ### Changed - Changed the way the "Open in system" option executes the WBRun command in AmigaOS 4, with a more secure way -- Did a lot of code cleanup in sync with the upstream, and parts that - were left over +- Did a lot of code cleanup in sync with the upstream, and parts of code + that were left over ### Fixed -- I did a lot of changes on path manipulation and usage, fixing opening +- I did a lot of changes on path manipulation and usage, fixing scanning the root of a partition or an assign path - Fixed an error with the codesets plugin, where an empty file could not be opened diff --git a/data/core/common.lua b/data/core/common.lua index ac337b00..092f7960 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -533,6 +533,13 @@ local function split_on_slash(s, sep_pattern) if s:match("^["..PATHSEP.."]") then t[#t + 1] = "" end + if (PLATFORM == "AmigaOS 4" or PLATFORM == "MorphOS") then + local drive = s:match("^([%w%s]*:)") + if drive then + t[#t + 1] = "" + s = s:gsub("^" .. drive, "") + end + end for fragment in string.gmatch(s, "([^"..PATHSEP.."]+)") do t[#t + 1] = fragment end @@ -555,6 +562,12 @@ function common.normalize_volume(filename) return drive:upper() .. rem end end + if (PLATFORM == "AmigaOS 4" or PLATFORM == "MorphOS") then + local drive, rem = filename:match('^([%w%s]*:)(.-)' .. PATHSEP .. '?$') + if drive then + return drive .. rem + end + end return filename end @@ -580,6 +593,11 @@ function common.normalize_path(filename) volume, filename = drive, rem end end + elseif (PLATFORM == "AmigaOS 4" or PLATFORM == "MorphOS") then + local drive, relpath = filename:match('^([%w%s]*:)(.+)') + if relpath then + volume, filename = drive, relpath + end else local relpath = filename:match('^/(.+)') if relpath then @@ -619,7 +637,7 @@ end ---@param path string The parent path. ---@return boolean function common.path_belongs_to(filename, path) - return string.find(filename, path .. PATHSEP, 1, true) == 1 + return string.find(filename, common.basepath(path), 1, true) == 1 end @@ -629,6 +647,9 @@ end ---@return boolean function common.relative_path(ref_dir, dir) local drive_pattern = "^(%a):\\" + if (PLATFORM == "AmigaOS 4" or PLATFORM == "MorphOS") then + drive_pattern = "^([%w%s]*:)" + end local drive, ref_drive = dir:match(drive_pattern), ref_dir:match(drive_pattern) if drive and ref_drive and drive ~= ref_drive then -- Windows, different drives, system.absolute_path fails for C:\..\D:\