public void setCurrentDirectory(final Variables vars, final FileObject dir) throws FileSystemException { assert vars != null; assert dir != null; log.trace("Setting CWD: {}", dir); // Make sure that the given file object exists and is really a directory if (!dir.exists()) { throw new RuntimeException("Directory not found: " + dir.getName()); } else if (!dir.getType().hasChildren()) { throw new RuntimeException("File can not contain children: " + dir.getName()); } vars.parent().set(CWD, dir); }
public Object call() throws Exception { FileObject toFile = root.resolveFile( to.path.string ); toFile.getParent().createFolder(); toFile.copyFrom( from, Selectors.SELECT_SELF ); toFile.getContent().setLastModifiedTime( to.lastModified.toDateTime().toDate().getTime() ); return Unit.unit(); } };
protected void keep(FileObject remoteDir, Set<String> names) throws TinkException, IOException { for (FileObject child : remoteDir.getChildren()) { if (!names.contains(child.getName().getBaseName())) { child.delete(new AllFileSelector()); } } }
public void touchFile(final FileObject file) { // this moves the file back on top getFile(file.getFileSystem(), file.getName()); } }
public static boolean hasChildren(final FileObject file) throws FileSystemException { assert file != null; if (file.getType().hasChildren()) { FileObject[] children = file.getChildren(); if (children != null && children.length != 0) { return true; } } return false; }
public Object call() throws Exception { root.resolveFile( path.string ).createFolder(); return Unit.unit(); } };
public static URI extractResourceDir(String dirname, boolean overwrite) throws FileSystemException, URISyntaxException { URL dir_url = EmbeddedJettyServer.class.getClassLoader().getResource(dirname); FileObject dir_jar = VFS.getManager().resolveFile(dir_url.toString()); String tempDir = FileUtils.getTempDirectory() + File.separator + System.getProperty("user.name").replace(" ", ""); FileObject tmpF = VFS.getManager().resolveFile(tempDir); FileObject localDir = tmpF.resolveFile(dirname); if (!localDir.exists()) { logger.info("Extracting directory " + dirname + " to " + tmpF.getName()); localDir.createFolder(); localDir.copyFrom(dir_jar, new AllFileSelector()); } else { if (overwrite) { logger.info("Overwritting directory " + dirname + " in " + tmpF.getName()); localDir.delete(new FileDepthSelector(0, 5)); localDir.createFolder(); localDir.copyFrom(dir_jar, new AllFileSelector()); } } resourceURI = localDir.getURL().toURI(); return resourceURI; }
public Object execute(final CommandContext context) throws Exception { assert context != null; IO io = context.getIo(); FileObject source = resolveFile(context, sourcePath); FileObject target = resolveFile(context, targetPath); ensureFileExists(source); // TODO: Validate more if (target.exists() && target.getType().hasChildren()) { target = target.resolveFile(source.getName().getBaseName()); } log.info("Copying {} -> {}", source, target); target.copyFrom(source, Selectors.SELECT_ALL); FileObjects.closeAll(source, target); return Result.SUCCESS; } }
FileObject file = fileSystemAccess.resolveFile(cwd, path); if (!file.exists()) { io.error("File not found: {}", file.getName()); return Result.FAILURE; else if (!file.getType().hasContent()) { io.error("File has no content: {}", file.getName()); return Result.FAILURE; log.debug("Sourcing file: {}", file.getName()); BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContent().getInputStream())); file.close();
FileObject file = fileSystemAccess.resolveFile(cwd, path); if (!file.exists()) { io.error("File not found: {}", file.getName()); return Result.FAILURE; else if (!file.getType().hasContent()) { io.error("File has not content: {}", file.getName()); return Result.FAILURE; else if (!file.isReadable()) { io.error("File is not readable: {}", file.getName()); return Result.FAILURE; return engine.eval(file.getName().getBaseName(), 1, 1, script); file.close();
/** * Get a list of direct descendents of the given resource. Note that attempts to get a list of * children does <emphasize>not</emphasize> result in an error. Instead an error message is * logged and an empty ArrayList returned. * * @return A <code>ArrayList</code> of VFSResources */ public List getChildren() { init(); ArrayList list = new ArrayList(); try { if ((resourceImpl != null) && resourceImpl.exists() && (resourceImpl.getType() == FileType.FOLDER)) { FileObject[] children = resourceImpl.getChildren(); for (int i = 0; i < children.length; i++) { FileObject child = children[i]; list.add(normalize(child.getName().getURI())); } } } catch (IOException e) { Message.debug(e); Message.verbose(e.getLocalizedMessage()); } return list; }
public static UnixFsObject.Directory dirFromFileObject( RelativePath toFile, FileObject fromFile, FileAttributes attributes ) throws FileSystemException { if ( !fromFile.getType().equals( FileType.FOLDER ) ) { throw new FileSystemException( "Not a directory: " + fromFile.getName().getPath() + ", was: " + fromFile.getType() ); } FileContent content = fromFile.getContent(); return UnixFsObject.directory( toFile, new LocalDateTime( content.getLastModifiedTime() ), attributes ); } }
private void resetChildrenList() { try { if (this.file.getType().hasChildren()) { this.children = new HashMap(); FileObject[] childrenList = this.file.getChildren(); for (int i = 0; i < childrenList.length; i++) { this.children.put(childrenList[i].getName(), new Object()); // null? } } } catch (FileSystemException fse) { this.children = null; } }
public static File asFile( FileObject fileObject ) { return new File( fileObject.getName().getPath() ); } }
/** * Creates a local copy of the file, and all its descendents. */ public File replicateFile(final FileObject srcFile, final FileSelector selector) throws FileSystemException { final String basename = srcFile.getName().getBaseName(); final File file = allocateFile(basename); // Copy from the source file final FileObject destFile = getContext().toFileObject(file); destFile.copyFrom(srcFile, selector); return file; } }
public Object execute(final CommandContext context) throws Exception { assert context != null; FileObject file = resolveFile(context, path); try { if (!file.exists()) { file.createFile(); } file.getContent().setLastModifiedTime(System.currentTimeMillis()); } finally { FileObjects.close(file); } return CommandAction.Result.SUCCESS; } }
/** * Returns the last modified time of this file. */ protected long doGetLastModifiedTime() throws Exception { return container.getContent().getLastModifiedTime(); }
/** * Handles an out-of-date file. */ protected void handleOutOfDateFile(final FileObject srcFile, final FileObject destFile) throws FileSystemException { log("Copying " + srcFile + " to " + destFile); destFile.copyFrom(srcFile, Selectors.SELECT_SELF); if (preserveLastModified && srcFile.getFileSystem().hasCapability(Capability.GET_LAST_MODIFIED) && destFile.getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FILE)) { final long lastModTime = srcFile.getContent().getLastModifiedTime(); destFile.getContent().setLastModifiedTime(lastModTime); } }