コード例 #1
0
ファイル: Uploads.java プロジェクト: ceylon/ceylon-herd
  public static void uploadRepo(Long id, @Required File repo, String module, String version)
      throws ZipException, IOException {
    models.Upload upload = Uploads.getUpload(id);
    File uploadsDir = Util.getUploadDir(upload.id);

    if (validationFailed()) {
      Uploads.uploadRepoForm(id);
    }

    String name = repo.getName().toLowerCase();

    if (name.endsWith(".zip")) uploadZip(repo, null, uploadsDir);
    else {
      boolean found = false;
      for (String postfix : SupportedExtensions) {
        if (name.endsWith(postfix)) {
          uploadArchive(repo, postfix, uploadsDir, module, version, id);
          found = true;
          break;
        }
      }
      if (!found)
        error(
            HttpURLConnection.HTTP_BAD_REQUEST,
            "Invalid uploaded file (must be zip, car, jar or src)");
    }

    Uploads.view(id);
  }
コード例 #2
0
ファイル: Uploads.java プロジェクト: ceylon/ceylon-herd
  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);
  }
コード例 #3
0
ファイル: Uploads.java プロジェクト: ceylon/ceylon-herd
  public static void deleteFile(Long id, String path, boolean returnToBrowse) throws IOException {
    models.Upload upload = Uploads.getUpload(id);
    File uploadsDir = Util.getUploadDir(upload.id);
    File file = new File(uploadsDir, path);

    deleteFileImpl(path, file, uploadsDir, upload);

    if (returnToBrowse) {
      File parent = file.getParentFile();
      String parentPath = JavaExtensions.relativeTo(parent, upload);
      // if we do viewFile directly we get silly %2F escapes in the URL
      redirect(Util.viewPublicUploadUrl(upload, parentPath));
    } else {
      Uploads.view(id);
    }
  }
コード例 #4
0
ファイル: Uploads.java プロジェクト: ceylon/ceylon-herd
  public static void deleteFileAsync(Long id, String path) throws IOException {
    models.Upload upload = Uploads.getUpload(id);
    File uploadsDir = Util.getUploadDir(upload.id);
    File file = new File(uploadsDir, path);

    deleteFileImpl(path, file, uploadsDir, upload);

    String message = Scope.Flash.current().get("message");
    renderJSON("{\"message\":\"" + message + "\"}");
  }
コード例 #5
0
ファイル: Uploads.java プロジェクト: ceylon/ceylon-herd
  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());
    }
  }
コード例 #6
0
ファイル: Uploads.java プロジェクト: ceylon/ceylon-herd
  public static void listFolder(Long id, String path) throws IOException {
    models.Upload upload = getUpload(id);
    File uploadsDir = Util.getUploadDir(upload.id);
    File file = new File(uploadsDir, path);
    Uploads.checkUploadPath(file, uploadsDir);

    if (!file.exists()) notFound(path);

    if (file.isDirectory()) {
      render("Uploads/listFolder.html", upload, file);
    } else {
      notFound();
    }
  }
コード例 #7
0
ファイル: Uploads.java プロジェクト: ceylon/ceylon-herd
 public static void uploadRepoForm(Long id) {
   models.Upload upload = Uploads.getUpload(id);
   render(upload);
 }