private boolean unzipModule( final ModuleIdentifier modID, final ModuleZipInfo zipInfo, boolean deleteZip) { // We synchronize to prevent a race whereby it tries to unzip the same module at the // same time (e.g. deployModule for the same module name has been called in parallel) String modName = modID.toString(); synchronized (modName.intern()) { if (!checkModDirs()) { return false; } File fdest = new File(modRoot, modName); File sdest = new File(systemModRoot, modName); if (fdest.exists() || sdest.exists()) { // This can happen if the same module is requested to be installed // at around the same time // It's ok if this happens log.warn("Module " + modID + " is already installed"); return true; } // Unzip into temp dir first File tdest = unzipIntoTmpDir(zipInfo, deleteZip); if (tdest == null) { return false; } // Check if it's a system module JsonObject conf = loadModuleConfig(modID, tdest); ModuleFields fields = new ModuleFields(conf); boolean system = fields.isSystem(); // Now copy it to the proper directory String moveFrom = tdest.getAbsolutePath(); try { vertx .fileSystem() .moveSync(moveFrom, system ? sdest.getAbsolutePath() : fdest.getAbsolutePath()); } catch (Exception e) { log.error("Failed to move module", e); return false; } log.info("Module " + modID + " successfully installed"); return true; } }
public synchronized void uninstallModule(String moduleName) { log.info("Uninstalling module " + moduleName + " from directory " + modRoot); File modDir = new File(modRoot, moduleName); if (!modDir.exists()) { log.error("Cannot find module to uninstall"); } else { try { vertx.fileSystem().deleteSync(modDir.getAbsolutePath(), true); log.info("Module " + moduleName + " successfully uninstalled"); } catch (Exception e) { log.error("Failed to delete directory: " + e.getMessage()); } } }
// We calculate a path adjustment that can be used by the fileSystem object // so that the *effective* working directory can be the module directory // this allows moduleRefs to read and write the file system as if they were // in the module dir, even though the actual working directory will be // wherever vertx run or vertx start was called from private void setPathAdjustment(File modDir) { Path cwd = Paths.get(".").toAbsolutePath().getParent(); Path pmodDir = Paths.get(modDir.getAbsolutePath()); Path relative = cwd.relativize(pmodDir); vertx.getContext().setPathAdjustment(relative); }