private static void uploadArchive( File file, String postfix, File uploadsDir, String module, String version, Long uploadId) throws IOException { try { // parse unless it's a jar and we have alternate info ModuleSpec spec; Logger.info("postfix: %s, module: %s, version: %s", postfix, module, version); if (postfix.equals(".jar") && (!StringUtils.isEmpty(module) || !StringUtils.isEmpty(version))) { Validation.required("module", module); if ("default".equals(module)) Validation.addError("module", "Default module not allowed"); Validation.required("version", version); if (validationFailed()) { Uploads.uploadRepoForm(uploadId); } spec = new ModuleSpec(module, version); } else { spec = ModuleSpec.parse(file.getName(), postfix); } // build dest file String path = spec.name.replace('.', File.separatorChar) + File.separatorChar + spec.version + File.separatorChar + spec.name + '-' + spec.version + postfix; File destFile = new File(uploadsDir, path); // check checkUploadPath(destFile, uploadsDir); if (destFile.isDirectory()) error( HttpURLConnection.HTTP_BAD_REQUEST, "Invalid path for upload: " + destFile.getName() + " (is a directory)"); // all good, let's copy destFile.getParentFile().mkdirs(); FileUtils.copyFile(file, destFile); // now let's sha1 it String sha1 = ModuleChecker.sha1(destFile); File sha1File = new File(uploadsDir, path + ".sha1"); FileUtils.write(sha1File, sha1); flash("message", "Uploaded archive file"); } catch (ModuleSpec.ModuleSpecException x) { error(HttpURLConnection.HTTP_BAD_REQUEST, x.getMessage()); } }
public static void addChecksum(Long id, String path) throws IOException { models.Upload upload = Uploads.getUpload(id); File uploadsDir = Util.getUploadDir(upload.id); File file = new File(uploadsDir, path); checkUploadPath(file, uploadsDir); if (!file.exists()) notFound(path); Logger.info("add checksum: %s exists: %s", path, file.exists()); String sha1 = ModuleChecker.sha1(file); File sha1File = new File(uploadsDir, path + ".sha1"); FileUtils.write(sha1File, sha1); Uploads.view(id); }