Package cloudsync.model

Examples of cloudsync.model.ItemType


    try {

      Path path = file.toPath();

      ItemType type = ItemType.UNKNOWN;

      if (Files.isSymbolicLink(path)) {

        String target;
        target = Files.readSymbolicLink(path).toString();
        final String firstChar = target.substring(0, 1);
        if (!firstChar.equals(Item.SEPARATOR)) {
          if (!firstChar.equals(".")) {
            target = "." + Item.SEPARATOR + target;
          }
          target = path.toString() + Item.SEPARATOR + target;
        }
        target = Paths.get(target).toFile().getCanonicalPath();

        if (!followlinks.equals(LinkType.NONE) && followlinks.equals(LinkType.EXTERNAL) && !target.startsWith(localPath)) {

          final Path targetPath = Paths.get(target);
          if (Files.exists(targetPath, LinkOption.NOFOLLOW_LINKS)) {
            path = targetPath;
          }
        }
      }

      BasicFileAttributes basic_attr = Files.readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
      final Long filesize = basic_attr.size();
      final FileTime creationTime = basic_attr.creationTime();
      final FileTime modifyTime = basic_attr.lastModifiedTime();
      final FileTime accessTime = basic_attr.lastAccessTime();

      if (basic_attr.isDirectory()) {
        type = ItemType.FOLDER;
      } else if (basic_attr.isRegularFile()) {
        type = ItemType.FILE;
      } else if (basic_attr.isSymbolicLink()) {
        type = ItemType.LINK;
      } else {
        type = ItemType.UNKNOWN;
      }

      Map<String, String[]> attributes = new HashMap<String, String[]>();

      PosixFileAttributeView posixView = Files.getFileAttributeView(path, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
      if (posixView != null) {
        final PosixFileAttributes attr = posixView.readAttributes();
        if (type.equals(ItemType.LINK)) {
          attributes.put(Item.ATTRIBUTE_POSIX, new String[] { attr.group().getName(), attr.owner().getName() });
        } else {
          attributes.put(Item.ATTRIBUTE_POSIX, new String[] { attr.group().getName(), attr.owner().getName(), fromPermissions(attr.permissions()).toString() });
        }
      } else {

        DosFileAttributeView dosView = Files.getFileAttributeView(path, DosFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
        if (dosView != null) {
          final DosFileAttributes attr = dosView.readAttributes();
          attributes.put(Item.ATTRIBUTE_DOS, new String[] { attr.isArchive() ? "1" : "0", attr.isHidden() ? "1" : "0", attr.isReadOnly() ? "1" : "0", attr.isSystem() ? "1" : "0" });
        }
      }

      if (!type.equals(ItemType.LINK)) {

        AclFileAttributeView aclView = Files.getFileAttributeView(path, AclFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
        if (aclView != null) {
          if (!attributes.containsKey(Item.ATTRIBUTE_POSIX))
            attributes.put(Item.ATTRIBUTE_OWNER, new String[] { aclView.getOwner().getName() });
View Full Code Here

TOP

Related Classes of cloudsync.model.ItemType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.