예제 #1
0
  /** Outputs the differences found between the archive and the file system. */
  private void diff() throws IOException {
    TarEntry entry;
    InputStream in = null;
    TarInputStream tin;
    File file;

    if ((in = openFileRead(archive)) == null) {
      exit(1);
    }

    if (decompress != 0) {
      in = wrapInputStream(in);
    }
    tin = new TarInputStream(in);

    while ((entry = tin.getNextEntry()) != null) {
      file = new File(entry.getName());

      if (!file.exists()) {
        out(file + ": Warning: No such file or directory");
        continue;
      }

      if (file.lastModified() != entry.getModTime().getTime()) {
        out(file + ": Mod time is different");
      }

      if (file.length() != entry.getSize()) {
        out(file + ": Size is different");
      }

      // TODO check file mode
      // TODO check file ownership
    }
  }
예제 #2
0
  // TODO
  private void update(File[] files) throws IOException {
    InputStream in;
    TarInputStream tin;
    TarEntry entry;
    TreeMap<String, Long> entries = new TreeMap<String, Long>();

    if ((in = openFileRead(archive)) == null) {
      fatal(" ", 1);
    }
    if (decompress != 0) {
      in = wrapInputStream(in);
    }

    tin = new TarInputStream(in);

    while ((entry = tin.getNextEntry()) != null) {
      entries.put(entry.getName(), entry.getModTime().getTime());
    }
    tin.close();

    long etime, ftime;
    ArrayList<File> list = new ArrayList<File>();
    for (File file : files) {
      if (entries.containsKey(file.getPath())) {
        etime = entries.get(file.getPath());
        ftime = file.lastModified();
        if (etime >= ftime) {
          continue;
        }
      }
      list.add(file);
    }

    insert(list.toArray(files));
  }
예제 #3
0
  /**
   * Extract entries from an archive.
   *
   * <p>TODO Need to parse Path for choosing specific files/directories either by direct naming or
   * by wildcard patterns. TODO Read list of entries to extract from FileList if its set.
   */
  private void extract() throws IOException {
    TarEntry entry;
    InputStream in = null;
    OutputStream out;
    TarInputStream tin;
    File file;

    if (archive != null) {
      if ((in = openFileRead(archive)) == null) {
        fatal(" ", 1);
      }
    } else {
      in = stdin;
    }

    if (decompress != 0) {
      in = wrapInputStream(in);
    }
    tin = new TarInputStream(in);

    if (use_stdout) {
      out = stdout;
    }

    while ((entry = tin.getNextEntry()) != null) {
      notice(entry.getName());
      file = new File(entry.getName());
      if (entry.isDirectory()) {
        if (!file.exists()) {
          file.mkdirs();
        }
        continue;
      } else {
        if (file.exists()) {
          if (keepOld || (keepNew && (file.lastModified() >= entry.getModTime().getTime()))) {
            continue;
          }
          if (backup) {
            file.renameTo(new File(file.getPath() + suffix));
          }
        }
      }
      if ((out = openFileWrite(file, true, true)) == null) {
        continue;
      }
      tin.copyEntryContents(out);
      out.close();
    }
    tin.close();
  }