From 9509dd4d07458af65e03b3487a11dff2bb053976 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Wed, 27 May 2009 11:30:51 +0000 Subject: Modified copy_file and move_file to overwrite existing file, only fail if existing directory. --- lib/fs.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/fs.lua b/lib/fs.lua index 962326c..872e62a 100644 --- a/lib/fs.lua +++ b/lib/fs.lua @@ -78,9 +78,9 @@ function create_file ( path ) end -- Copies a file to a directory or new filename (creating the directory if necessary) --- fails if new file already exists +-- fails if new file is already a directory function copy_file(oldpath, newpath) - if not is_file(oldpath) or not newpath or newpath == "" or (basename(newpath) ~= "" and posix.stat(newpath)) or (basename(newpath) == "" and posix.stat(newpath .. basename(oldpath))) then + if not is_file(oldpath) or not newpath or newpath == "" or (basename(newpath) ~= "" and is_dir(newpath)) or (basename(newpath) == "" and is_dir(newpath .. basename(oldpath))) then return false end if dirname(newpath) and not posix.stat(dirname(newpath)) then create_directory(dirname(newpath)) end @@ -94,9 +94,9 @@ function copy_file(oldpath, newpath) end -- Moves a file to a directory or new filename (creating the directory if necessary) --- fails if new file already exists +-- fails if new file is already a directory function move_file(oldpath, newpath) - if not is_file(oldpath) or not newpath or newpath == "" or (basename(newpath) ~= "" and posix.stat(newpath)) or (basename(newpath) == "" and posix.stat(newpath .. basename(oldpath))) then + if not is_file(oldpath) or not newpath or newpath == "" or (basename(newpath) ~= "" and is_dir(newpath)) or (basename(newpath) == "" and is_dir(newpath .. basename(oldpath))) then return false end if dirname(newpath) and not posix.stat(dirname(newpath)) then create_directory(dirname(newpath)) end -- cgit v1.2.3