Beispiel #1
0
  @Override
  public void execute() throws IOException {
    Attributes remoteAttributes = remoteIndex.get(path);
    Path rootDirectory = Registry.getInstance().getRootDirectory();

    try {
      // TODO get rid of getRootDirectory, stupid (non)dependency
      new NetworkClient(rootDirectory).request(remoteAttributes.getAddress(), path);
    } catch (URISyntaxException e) {
      logger.error(e);
    }

    if (logger.isTraceEnabled()) {}

    logger.trace(
        String.format("Setting time on %1s to %2s", path, remoteAttributes.lastModifiedTime()));

    rootDirectory
        .resolve(path)
        .setAttribute(
            "basic:lastModifiedTime",
            FileTime.fromMillis(remoteAttributes.lastModifiedTime()),
            LinkOption.NOFOLLOW_LINKS);

    localIndex.addFromRemote(path, remoteAttributes);
  }
Beispiel #2
0
 public void touch(Path fileToTouch) throws IOException {
   if (exists(fileToTouch)) {
     setLastModifiedTime(fileToTouch, FileTime.fromMillis(System.currentTimeMillis()));
   } else {
     createNewFile(fileToTouch);
   }
 }
  public FakeProjectFilesystem(Clock clock, Path root, Set<Path> files) {
    super(root);
    // We use LinkedHashMap to preserve insertion order, so the
    // behavior of this test is consistent across versions. (It also lets
    // us write tests which explicitly test iterating over entries in
    // different orders.)
    fileContents = new LinkedHashMap<>();
    fileLastModifiedTimes = new LinkedHashMap<>();
    FileTime modifiedTime = FileTime.fromMillis(clock.currentTimeMillis());
    for (Path file : files) {
      fileContents.put(file, new byte[0]);
      fileLastModifiedTimes.put(file, modifiedTime);
    }
    fileAttributes = new LinkedHashMap<>();
    symLinks = new LinkedHashMap<>();
    directories = new LinkedHashSet<>();
    directories.add(Paths.get(""));
    for (Path file : files) {
      Path dir = file.getParent();
      while (dir != null) {
        directories.add(dir);
        dir = dir.getParent();
      }
    }
    this.clock = Preconditions.checkNotNull(clock);

    // Generally, tests don't care whether files exist.
    ignoreValidityOfPaths = true;
  }
Beispiel #4
0
 // do not make updateLastAccessed synchronized
 public static void updateLastAccessed(File file) {
   try {
     Files.setAttribute(
         file.toPath(), "lastAccessTime", FileTime.fromMillis(new Date().getTime()));
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 @Override
 public void mkdirs(Path path) throws IOException {
   for (int i = 0; i < path.getNameCount(); i++) {
     Path subpath = path.subpath(0, i + 1);
     directories.add(subpath);
     fileLastModifiedTimes.put(subpath, FileTime.fromMillis(clock.currentTimeMillis()));
   }
 }
Beispiel #6
0
  public static void setModifiedTime(Path filePath, long modifiedTime) throws IOException {

    if (!Files.exists(filePath)) {
      return;
    }

    FileTime fileTime = FileTime.fromMillis(modifiedTime);

    Files.setLastModifiedTime(filePath, fileTime);
  }
  @Override
  public void writeBytesToPath(byte[] bytes, Path path, FileAttribute<?>... attrs)
      throws IOException {
    Path normalizedPath = MorePaths.normalize(path);
    fileContents.put(normalizedPath, Preconditions.checkNotNull(bytes));
    fileAttributes.put(normalizedPath, ImmutableSet.copyOf(attrs));

    Path directory = normalizedPath.getParent();
    while (directory != null) {
      directories.add(directory);
      directory = directory.getParent();
    }
    fileLastModifiedTimes.put(normalizedPath, FileTime.fromMillis(clock.currentTimeMillis()));
  }
 public FileTime secondFileTime(FileTime lastModif) {
   long millis = lastModif.toMillis();
   long diff = millis % 1000;
   return FileTime.fromMillis(millis - diff);
 }
 private void setFileCreationDate(File f, long time) throws IOException {
   BasicFileAttributeView attributes =
       Files.getFileAttributeView(f.toPath(), BasicFileAttributeView.class);
   FileTime creationTime = FileTime.fromMillis(time);
   attributes.setTimes(creationTime, creationTime, creationTime);
 }
Beispiel #10
0
 public SourceId locateModule(ModulePath modulePath, long mtime) {
   return new SourceId(modulePath, FileTime.fromMillis(mtime));
 }