Exemple #1
0
 /** Check whether the filepath could be created */
 public boolean isValidToCreate(UTF8 src) {
   String srcs = normalizePath(src);
   synchronized (rootDir) {
     if (srcs.startsWith("/") && !srcs.endsWith("/") && rootDir.getNode(srcs) == null) {
       return true;
     } else {
       return false;
     }
   }
 }
Exemple #2
0
 /** Get the blocks associated with the file */
 public Block[] getFile(UTF8 src) {
   waitForReady();
   synchronized (rootDir) {
     INode targetNode = rootDir.getNode(src.toString());
     if (targetNode == null) {
       return null;
     } else {
       return targetNode.blocks;
     }
   }
 }
Exemple #3
0
    INode getNode(Vector components, int index) {
      if (!name.equals((String) components.elementAt(index))) {
        return null;
      }
      if (index == components.size() - 1) {
        return this;
      }

      // Check with children
      INode child = (INode) children.get(components.elementAt(index + 1));
      if (child == null) {
        return null;
      } else {
        return child.getNode(components, index + 1);
      }
    }
Exemple #4
0
  /**
   * Get a listing of files given path 'src'
   *
   * <p>This function is admittedly very inefficient right now. We'll make it better later.
   */
  public DFSFileInfo[] getListing(UTF8 src) {
    String srcs = normalizePath(src);

    synchronized (rootDir) {
      INode targetNode = rootDir.getNode(srcs);
      if (targetNode == null) {
        return null;
      } else {
        Vector contents = new Vector();
        targetNode.listContents(contents);

        DFSFileInfo listing[] = new DFSFileInfo[contents.size()];
        int i = 0;
        for (Iterator it = contents.iterator(); it.hasNext(); i++) {
          listing[i] = new DFSFileInfo((INode) it.next());
        }
        return listing;
      }
    }
  }
Exemple #5
0
 Block[] unprotectedDelete(UTF8 src) {
   synchronized (rootDir) {
     INode targetNode = rootDir.getNode(src.toString());
     if (targetNode == null) {
       return null;
     } else {
       //
       // Remove the node from the namespace and GC all
       // the blocks underneath the node.
       //
       if (!targetNode.removeNode()) {
         return null;
       } else {
         Vector v = new Vector();
         targetNode.collectSubtreeBlocks(v);
         for (Iterator it = v.iterator(); it.hasNext(); ) {
           Block b = (Block) it.next();
           activeBlocks.remove(b);
         }
         return (Block[]) v.toArray(new Block[v.size()]);
       }
     }
   }
 }
Exemple #6
0
 boolean unprotectedRenameTo(UTF8 src, UTF8 dst) {
   synchronized (rootDir) {
     INode removedNode = rootDir.getNode(src.toString());
     if (removedNode == null) {
       return false;
     }
     removedNode.removeNode();
     if (isDir(dst)) {
       dst = new UTF8(dst.toString() + "/" + new File(src.toString()).getName());
     }
     INode newNode = rootDir.addNode(dst.toString(), removedNode.blocks);
     if (newNode != null) {
       newNode.children = removedNode.children;
       for (Iterator it = newNode.children.values().iterator(); it.hasNext(); ) {
         INode child = (INode) it.next();
         child.parent = newNode;
       }
       return true;
     } else {
       rootDir.addNode(src.toString(), removedNode.blocks);
       return false;
     }
   }
 }
Exemple #7
0
 /** Check whether the path specifies a directory */
 public boolean isDir(UTF8 src) {
   synchronized (rootDir) {
     INode node = rootDir.getNode(normalizePath(src));
     return node != null && node.isDir();
   }
 }