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 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

View File

@ -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:\