v2.1.1 - Fixed copying/moving directories from different drives
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
local agcfg = {
|
local agcfg = {
|
||||||
["halyde"] = {
|
["halyde"] = {
|
||||||
["maindir"] = "",
|
["maindir"] = "",
|
||||||
["version"] = "2.1.0",
|
["version"] = "2.1.1",
|
||||||
["description"] = "A universal, customizable and feature-packed operating system for OpenComputers.",
|
["description"] = "A universal, customizable and feature-packed operating system for OpenComputers.",
|
||||||
["directories"] = {
|
["directories"] = {
|
||||||
"halyde/apps",
|
"halyde/apps",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
local loadfile = ...
|
local loadfile = ...
|
||||||
local filesystem = loadfile("/halyde/lib/filesystem.lua")(loadfile)
|
local filesystem = loadfile("/halyde/lib/filesystem.lua")(loadfile)
|
||||||
|
|
||||||
_G._OSVERSION = "Halyde 2.1.0"
|
_G._OSVERSION = "Halyde 2.1.1"
|
||||||
_G._OSLOGO = ""
|
_G._OSLOGO = ""
|
||||||
local handle, tmpdata = filesystem.open("/halyde/config/oslogo.ans", "r"), nil
|
local handle, tmpdata = filesystem.open("/halyde/config/oslogo.ans", "r"), nil
|
||||||
repeat
|
repeat
|
||||||
|
|||||||
+51
-10
@@ -209,6 +209,50 @@ function filesystem.size(path)
|
|||||||
return component.invoke(address, "size", absPath)
|
return component.invoke(address, "size", absPath)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function getRecursiveList(address,absPath)
|
||||||
|
local list = component.invoke(address,"list",absPath)
|
||||||
|
local dirList = {}
|
||||||
|
local listChanged = true
|
||||||
|
while listChanged do
|
||||||
|
listChanged = false
|
||||||
|
for i=1,#list do
|
||||||
|
if component.invoke(address, "isDirectory", absPath.."/"..list[i]) then
|
||||||
|
listChanged = true
|
||||||
|
local dir = list[i]
|
||||||
|
if dir:sub(-1)=="/" then dir=dir:sub(1,-2) end
|
||||||
|
table.insert(dirList,dir)
|
||||||
|
table.remove(list,i)
|
||||||
|
local subDir = component.invoke(address,"list",absPath.."/"..dir)
|
||||||
|
for j=1,#subDir do table.insert(list,dir.."/"..subDir[j]) end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return list,dirList
|
||||||
|
end
|
||||||
|
|
||||||
|
local function copyRecursive(fromAddress,fromAbsPath,toAddress,toAbsPath)
|
||||||
|
if fromAbsPath:sub(-1)=="/" then fromAbsPath=fromAbsPath:sub(1,-2) end
|
||||||
|
if toAbsPath:sub(-1)=="/" then toAbsPath=toAbsPath:sub(1,-2) end
|
||||||
|
component.invoke(toAddress,"makeDirectory",toAbsPath)
|
||||||
|
local fileList,dirList = getRecursiveList(fromAddress,fromAbsPath)
|
||||||
|
for i=1,#dirList do
|
||||||
|
component.invoke(toAddress,"makeDirectory",toAbsPath.."/"..dirList[i])
|
||||||
|
end
|
||||||
|
for i=1,#fileList do
|
||||||
|
local fromFile, toFile = fromAbsPath.."/"..fileList[i], toAbsPath.."/"..fileList[i]
|
||||||
|
local handle = component.invoke(fromAddress, "open", fromFile, "r")
|
||||||
|
local data, tmpdata = "", nil
|
||||||
|
repeat
|
||||||
|
tmpdata = component.invoke(fromAddress, "read", handle, math.huge or math.maxinteger)
|
||||||
|
data = data .. (tmpdata or "")
|
||||||
|
until not tmpdata
|
||||||
|
tmpdata = component.invoke(fromAddress, "close", handle)
|
||||||
|
local handle = component.invoke(toAddress, "open", toFile, "w")
|
||||||
|
component.invoke(toAddress, "write", handle, data)
|
||||||
|
component.invoke(toAddress, "close", handle)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function filesystem.rename(fromPath, toPath)
|
function filesystem.rename(fromPath, toPath)
|
||||||
checkArg(1, fromPath, "string")
|
checkArg(1, fromPath, "string")
|
||||||
checkArg(2, toPath, "string")
|
checkArg(2, toPath, "string")
|
||||||
@@ -219,6 +263,9 @@ function filesystem.rename(fromPath, toPath)
|
|||||||
end
|
end
|
||||||
if fromAddress == toAddress then
|
if fromAddress == toAddress then
|
||||||
return component.invoke(fromAddress, "rename", fromAbsPath, toAbsPath)
|
return component.invoke(fromAddress, "rename", fromAbsPath, toAbsPath)
|
||||||
|
elseif component.invoke(fromAddress, "isDirectory", fromAbsPath) then
|
||||||
|
copyRecursive(fromAddress,fromAbsPath,toAddress,toAbsPath)
|
||||||
|
component.invoke(fromAddress,"remove", fromAbsPath)
|
||||||
else
|
else
|
||||||
local handle, data, tmpdata = component.invoke(fromAddress, "open", fromAbsPath, "r"), "", nil
|
local handle, data, tmpdata = component.invoke(fromAddress, "open", fromAbsPath, "r"), "", nil
|
||||||
repeat
|
repeat
|
||||||
@@ -241,6 +288,9 @@ function filesystem.copy(fromPath, toPath)
|
|||||||
if not fromAddress or not toAddress then
|
if not fromAddress or not toAddress then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
if component.invoke(fromAddress, "isDirectory", fromAbsPath) then
|
||||||
|
copyRecursive(fromAddress,fromAbsPath,toAddress,toAbsPath)
|
||||||
|
else
|
||||||
local handle = component.invoke(fromAddress, "open", fromAbsPath, "r")
|
local handle = component.invoke(fromAddress, "open", fromAbsPath, "r")
|
||||||
local data, tmpdata = "", nil
|
local data, tmpdata = "", nil
|
||||||
repeat
|
repeat
|
||||||
@@ -252,6 +302,7 @@ function filesystem.copy(fromPath, toPath)
|
|||||||
component.invoke(toAddress, "write", handle, data)
|
component.invoke(toAddress, "write", handle, data)
|
||||||
component.invoke(toAddress, "close", handle)
|
component.invoke(toAddress, "close", handle)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function filesystem.isDirectory(path)
|
function filesystem.isDirectory(path)
|
||||||
checkArg(1, path, "string")
|
checkArg(1, path, "string")
|
||||||
@@ -280,16 +331,6 @@ function filesystem.makeDirectory(path)
|
|||||||
return component.invoke(address, "makeDirectory", absPath)
|
return component.invoke(address, "makeDirectory", absPath)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function randomHex(length)
|
|
||||||
local chars = "0123456789abcdef"
|
|
||||||
local result = ""
|
|
||||||
for i = 1, length do
|
|
||||||
local index = math.random(1, #chars)
|
|
||||||
result = result .. string.sub(chars, index, index)
|
|
||||||
end
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
|
|
||||||
function filesystem.makeReadStream(content)
|
function filesystem.makeReadStream(content)
|
||||||
local properHandle = {}
|
local properHandle = {}
|
||||||
local readcursor = 1
|
local readcursor = 1
|
||||||
|
|||||||
Reference in New Issue
Block a user