diff --git a/src/spm/spm.lua b/src/spm/spm.lua index 9ba1627..a6e90ae 100644 --- a/src/spm/spm.lua +++ b/src/spm/spm.lua @@ -475,6 +475,48 @@ local function installPackage(requestedPackage, installPath, doUpdate) print("Successfully installed package " .. requestedPackage) end +local function copyPackage(requestedPackage, copyLocation) + local packageInformation, repositoryLocation = getInformation(requestedPackage) + if not packageInformation then + print("Package does not exist") + return + end + + local locallyInstalledFiles = readFromLocalInstallFile() + if not locallyInstalledFiles then + io.stderr:write("Error while trying to read package names") + return + elseif locallyInstalledFiles[1] == -1 then + table.remove(locallyInstalledFiles, 1) + end + + if not locallyInstalledFiles[requestedPackage] then + print("Package has not been installed.") + print("It must be installed to be copied.") + return + end + + term.write("Copying package files...") + for installedFilePath, fileLocalInstallPath in pairs(locallyInstalledFiles[requestedPackage]) do + fs.copy(fileLocalInstallPath, copyLocation .. fileLocalInstallPath) + end + + if packageInfo.dependencies then + term.write("Done\nCopying Dependencies...") + for packageDependency, _ in pairs(packageInfo.dependencies) do + if not locallyInstalledFiles[packageDependency] then + print("Dependency has not been installed.") + print("If it has, it is not recognized. Reinstall the parent package: " .. requestedPackage) + return + end + copyPackage(packageDependency, copyLocation) + end + end + + term.write("Done.\n") + print("Successfully copied package " .. requestedPackage) +end + local function uninstallPackage(requestedPackage) local packageInformation, repositoryLocation = getInformation(requestedPackage) if not packageInformation then @@ -542,6 +584,8 @@ elseif args[1] == "update" or args[1] == "upgrade" then updatePackage(args[2]) elseif args[1] == "uninstall" or args[1] == "remove" then uninstallPackage(args[2]) +elseif args[1] == "copy" then + copyPackage(args[2], args[3]) else printUsage() return