From 2321c7ad5ab98d0be3b932f00bb91601b313cef9 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Thu, 10 Apr 2014 10:04:49 -0400 Subject: Fixed bug introduced by r1710 relating to absolute paths. --- core/args.lua | 2 +- core/file_io.lua | 2 +- core/lfs_ext.lua | 12 +++++++----- 3 files changed, 9 insertions(+), 7 deletions(-) (limited to 'core') diff --git a/core/args.lua b/core/args.lua index 6fd18841..cc34e837 100644 --- a/core/args.lua +++ b/core/args.lua @@ -57,7 +57,7 @@ function M.process(arg) f(table.unpack(args)) i = i + n else - io.open_file(lfs.abspath(arg[i])) + io.open_file(lfs.abspath(arg[i], arg[-1])) no_args = false end i = i + 1 diff --git a/core/file_io.lua b/core/file_io.lua index 264de408..6b860e3b 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -114,7 +114,7 @@ function io.open_file(filenames) } if not filenames then return end for i = 1, #filenames do - local filename = lfs.abspath(filenames[i]:gsub('^file://', '')) + local filename = lfs.abspath((filenames[i]:gsub('^file://', ''))) for i, buffer in ipairs(_BUFFERS) do if filename == buffer.filename then view:goto_buffer(i) goto continue end end diff --git a/core/lfs_ext.lua b/core/lfs_ext.lua index 7fe04b89..3b857477 100644 --- a/core/lfs_ext.lua +++ b/core/lfs_ext.lua @@ -96,14 +96,16 @@ end --- -- Returns the absolute path to string *filename*. --- `lfs.currentdir()` is prepended to a relative filename. The returned path is --- not guaranteed to exist. +-- *prefix* or `lfs.currentdir()` is prepended to a relative filename. The +-- returned path is not guaranteed to exist. -- @param filename The relative or absolute path to a file. -- @return string absolute path -function lfs.abspath(filename) - if filename:find(not WIN32 and '^/' or '^%a:[/\\]') then return filename end +function lfs.abspath(filename, prefix) if WIN32 then filename = filename:gsub('/', '\\') end - filename = lfs.currentdir()..(not WIN32 and '/' or '\\')..filename + if not filename:find(not WIN32 and '^/' or '^%a:[/\\]') then + prefix = prefix or lfs.currentdir() + filename = prefix..(not WIN32 and '/' or '\\')..filename + end filename = filename:gsub('%f[^/\\]%.[/\\]', '') -- clean up './' while filename:find('[^/\\]+[/\\]%.%.[/\\]') do filename = filename:gsub('[^/\\]+[/\\]%.%.[/\\]', '') -- clean up '../' -- cgit v1.2.3