More fixes with the relative paths

This commit is contained in:
George Sokianos 2024-02-19 00:56:45 +00:00
parent 7efe75fe7d
commit 1be1c7fb0b
2 changed files with 25 additions and 4 deletions

View File

@ -237,11 +237,11 @@ https://git.walkero.gr/walkero/lite-xl/issues
### Changed ### Changed
- Changed the way the "Open in system" option executes the WBRun command - Changed the way the "Open in system" option executes the WBRun command
in AmigaOS 4, with a more secure way in AmigaOS 4, with a more secure way
- Did a lot of code cleanup in sync with the upstream, and parts that - Did a lot of code cleanup in sync with the upstream, and parts of code
were left over that were left over
### Fixed ### 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 the root of a partition or an assign path
- Fixed an error with the codesets plugin, where an empty file could - Fixed an error with the codesets plugin, where an empty file could
not be opened not be opened

View File

@ -533,6 +533,13 @@ local function split_on_slash(s, sep_pattern)
if s:match("^["..PATHSEP.."]") then if s:match("^["..PATHSEP.."]") then
t[#t + 1] = "" t[#t + 1] = ""
end 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 for fragment in string.gmatch(s, "([^"..PATHSEP.."]+)") do
t[#t + 1] = fragment t[#t + 1] = fragment
end end
@ -555,6 +562,12 @@ function common.normalize_volume(filename)
return drive:upper() .. rem return drive:upper() .. rem
end end
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 return filename
end end
@ -580,6 +593,11 @@ function common.normalize_path(filename)
volume, filename = drive, rem volume, filename = drive, rem
end end
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 else
local relpath = filename:match('^/(.+)') local relpath = filename:match('^/(.+)')
if relpath then if relpath then
@ -619,7 +637,7 @@ end
---@param path string The parent path. ---@param path string The parent path.
---@return boolean ---@return boolean
function common.path_belongs_to(filename, path) 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 end
@ -629,6 +647,9 @@ end
---@return boolean ---@return boolean
function common.relative_path(ref_dir, dir) function common.relative_path(ref_dir, dir)
local drive_pattern = "^(%a):\\" 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) local drive, ref_drive = dir:match(drive_pattern), ref_dir:match(drive_pattern)
if drive and ref_drive and drive ~= ref_drive then if drive and ref_drive and drive ~= ref_drive then
-- Windows, different drives, system.absolute_path fails for C:\..\D:\ -- Windows, different drives, system.absolute_path fails for C:\..\D:\