コード例 #1
0
  MetaDataFileInfo(String fileName, MetaDataDedupFile mf) {
    this.fileName = fileName;
    this.mf = mf;
    this.isDirectory = mf.isDirectory();
    fileIndex = getNextFileIndex();
    Path file = Paths.get(mf.getPath());
    try {
      DosFileAttributes attr = Files.readAttributes(file, DosFileAttributes.class);
      if (attr.isArchive()) fileAttribute |= FileAttributeFlags.FILE_ATTRIBUTE_ARCHIVE.getValue();
      if (attr.isDirectory())
        fileAttribute |= FileAttributeFlags.FILE_ATTRIBUTE_DIRECTORY.getValue();
      if (attr.isHidden()) fileAttribute |= FileAttributeFlags.FILE_ATTRIBUTE_HIDDEN.getValue();
      if (attr.isReadOnly()) fileAttribute |= FileAttributeFlags.FILE_ATTRIBUTE_READONLY.getValue();
      if (attr.isRegularFile())
        fileAttribute |= FileAttributeFlags.FILE_ATTRIBUTE_NORMAL.getValue();
      if (attr.isSymbolicLink())
        fileAttribute |= FileAttributeFlags.FILE_ATTRIBUTE_REPARSE_POINT.getValue();
      if (attr.isSystem()) fileAttribute |= FileAttributeFlags.FILE_ATTRIBUTE_SYSTEM.getValue();
    } catch (IOException | UnsupportedOperationException x) {
      SDFSLogger.getLog().error("attributes could not be created for " + this.fileName, x);
    }

    creationTime = FileTimeUtils.toFileTime(new Date(0));
    lastAccessTime = FileTimeUtils.toFileTime(new Date(mf.getLastAccessed()));
    lastWriteTime = FileTimeUtils.toFileTime(new Date(mf.lastModified()));
    fileSize = mf.length();
    SDFSLogger.getLog().debug("created file info for " + fileName);
  }
コード例 #2
0
ファイル: FileUtil.java プロジェクト: jayatheerthan/syncany
  public static String dosAttrsToString(DosFileAttributes dosAttrs) {
    StringBuilder sb = new StringBuilder();

    sb.append(dosAttrs.isReadOnly() ? "r" : "-");
    sb.append(dosAttrs.isHidden() ? "h" : "-");
    sb.append(dosAttrs.isArchive() ? "a" : "-");
    sb.append(dosAttrs.isSystem() ? "s" : "-");

    return sb.toString();
  }
コード例 #3
0
ファイル: PathName.java プロジェクト: henryx/memento-java
  public FileAttrs getAttrs() throws IOException {
    FileAttrs result;
    BasicFileAttributes attr;
    DosFileAttributes dosAttr;
    PosixFileAttributes posixAttr;

    result = new FileAttrs();
    attr = Files.readAttributes(this.path.toPath(), BasicFileAttributes.class);

    result.setCtime(attr.creationTime().toMillis());
    result.setMtime(attr.lastModifiedTime().toMillis());
    // result.append("symlink", attr.isSymbolicLink()); //Redundant
    result.setSize(attr.size());

    if (System.getProperty("os.name").startsWith("Windows")) {
      dosAttr = Files.readAttributes(this.path.toPath(), DosFileAttributes.class);

      result.setDosArchive(dosAttr.isArchive());
      result.setDosHidden(dosAttr.isHidden());
      result.setDosReadonly(dosAttr.isReadOnly());
      result.setDosSystem(dosAttr.isSystem());
    } else {
      posixAttr = Files.readAttributes(this.path.toPath(), PosixFileAttributes.class);

      result.setPosixSymlink(this.isSymlink());

      if (result.getPosixSymlink()) {
        result.setLinkTo(Files.readSymbolicLink(this.path.toPath()).toString());
      }

      result.setPosixOwner(posixAttr.owner().getName());
      result.setPosixGroup(posixAttr.group().getName());
      result.setPosixPermission(PosixFilePermissions.toString(posixAttr.permissions()));
    }

    return result;
  }
コード例 #4
0
 static void checkDosAttributes(DosFileAttributes attrs1, DosFileAttributes attrs2) {
   assertTrue(attrs1.isReadOnly() == attrs2.isReadOnly());
   assertTrue(attrs1.isHidden() == attrs2.isHidden());
   assertTrue(attrs1.isSystem() == attrs2.isSystem());
 }