/** * Create localconf folder and properties file necessary to run build task in order to check merge integrity. * @param branchName */ public void createLocalConfigFile(String branchName) throws Exception { String branchPath = SvnUtils.TEMP_FOLDER + "/" + branchName; //create localconf directory String newDirectoryPath = branchPath + "/localconf"; if ( !Files.exists( Paths.get(newDirectoryPath))) { Set<PosixFilePermission> permissions = PosixFilePermissions.fromString("rwxrwxrwx"); FileAttribute<Set<PosixFilePermission>> fileAttributes = PosixFilePermissions .asFileAttribute(permissions); Files.createDirectory(Paths.get(newDirectoryPath), fileAttributes); } //copy properties template Files.copy( Paths.get(branchPath + "/common/conf/worldnettps.properties.template"), Paths.get(newDirectoryPath + "/worldnettps.properties"), StandardCopyOption.REPLACE_EXISTING); //setting glassfish directory in properties file String appServerDir = PropertiesUtil.getString("appserver.dir"); String sedCommand = String.format( "sed -i '/glassfish.dir/c\\glassfish.dir=%s' localconf/worldnettps.properties", appServerDir); CommandExecutor.run( sedCommand, branchPath); logger.info("worldnettps.properties file has been created in localconf folder."); }
@Override public int create(String path, @mode_t long mode, FuseFileInfo fi) { try { Set<OpenFlags> flags = bitMaskUtil.bitMaskToSet(OpenFlags.class, fi.flags.longValue()); LOG.info("createAndOpen {} with openOptions {}", path, flags); Path node = resolvePath(path); if (fileStore.supportsFileAttributeView(PosixFileAttributeView.class)) { FileAttribute<?> attrs = PosixFilePermissions.asFileAttribute(attrUtil.octalModeToPosixPermissions(mode)); return fileHandler.createAndOpen(node, fi, attrs); } else { return fileHandler.createAndOpen(node, fi); } } catch (RuntimeException e) { LOG.error("create failed.", e); return -ErrorCodes.EIO(); } }
/** * File access is checked using {@link #checkAccess(BlobStoreContext, CloudPath, Set)} * always with {@link AclEntryPermission#WRITE_DATA} and {@link AclEntryPermission#ADD_FILE}, * and optionally with {@link AclEntryPermission#APPEND_DATA} if <em>options</em> contains * {@link StandardOpenOption#APPEND}. * @see CloudFileChannel */ @Override public CloudFileChannel newByteChannel(BlobStoreContext context, CloudPath path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException { EnumSet<AclEntryPermission> channelPerms = EnumSet.noneOf(AclEntryPermission.class); options.forEach(o -> { AclEntryPermission aclPerm = openOptionToAclEntryPermission(o); if (aclPerm != null) { channelPerms.add(aclPerm); } }); // Check the parent path for file add if (channelPerms.remove(AclEntryPermission.ADD_FILE)) { checkAccess(context, path.getParent(), CREATE_NEW_FILE_PERMS); } // Check file access if the file exists if (path.exists()) { checkAccess(context, path, channelPerms); } // Create the channel return new CloudFileChannel(context, path, getCloudFileChannelTransport(), options, attrs); }
public SeekableByteChannel newByteChannel( Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs ) throws IOException { boolean append = true; if( options.contains( StandardOpenOption.APPEND ) ) { append = true; } else if( options.contains( StandardOpenOption.TRUNCATE_EXISTING ) ) { append = false; } if( options.contains( StandardOpenOption.READ ) ) { return new MemChannel.Read( buffer ); } if( options.contains( StandardOpenOption.WRITE ) ) { if( !append ) { truncate(); } return new MemChannel.Appender( buffer ); } throw new IOException( "Must read or write" ); }
/** * Creates and returns a new {@link SeekableSMBByteChannel} instance. * * @param path The {@link SMBPath} for which a byte channel should be opened. * @param options A set of {@link StandardOpenOption}s. * @param attrs An optional list of file attributes to set when creating the file. * @return An instance of {@link SeekableSMBByteChannel}. * * @throws IllegalArgumentException If provided path is not an {@link SMBPath} instance. * @throws IOException If an I/O error occurs * @throws UnsupportedOperationException If an unsupported open option is specified (DSYNC, SYNC or SPARSE) */ @Override public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException { /* Convert path and instantiate SmbFile. */ final SMBPath smbPath = SMBPath.fromPath(path); final SmbFile file = smbPath.getSmbFile(); /* Determines how the SeekableByteChannel should be setup. */ boolean write = false; boolean create = false; boolean create_new = false; boolean append = false; boolean truncate = false; for (OpenOption option : options) { if (option.equals(StandardOpenOption.WRITE)) { write = true; } else if (option.equals(StandardOpenOption.CREATE)) { create = true; } else if (option.equals(StandardOpenOption.CREATE_NEW)) { create_new = true; } else if (option.equals(StandardOpenOption.APPEND)) { append = true; } else if (option.equals(StandardOpenOption.TRUNCATE_EXISTING)) { truncate = true; } else if (option.equals(StandardOpenOption.DSYNC) || option.equals(StandardOpenOption.SYNC) || option.equals(StandardOpenOption.SPARSE) || option.equals(StandardOpenOption.DELETE_ON_CLOSE)) { throw new UnsupportedOperationException("SMBFileSystemProvider does not support the option options SYNC, DSYNC, SPARSE or DELETE_ON_CLOSE"); } } /* Returns a new SeekableSMBByteChannel object. */ return new SeekableSMBByteChannel(file, write, create, create_new, truncate, append); }
@Override public SeekableByteChannel newByteChannel( Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException { return promote(path).newByteChannel(options, attrs); }
public List<Path> createFiles(Path directory, int number) throws IOException { if (directory == null) { throw new NullPointerException("Path passed to createFiles cannot be null"); } FileAttribute<?>[] attrs = {}; System.out.println("Creating " + number + " files in " + directory); Files.createDirectories(directory, attrs); assertTrue("Directory was not created", Files.exists(directory)); List<Path> files = new LinkedList<Path>(); for (int counter = 0; counter < number; counter++) { Path newFile; synchronized (file_counter_lock) { newFile = directory.resolve("file" + file_counter++ + ".txt"); } Files.createFile(newFile, attrs); assertTrue("File was not created", Files.exists(newFile)); files.add(newFile); } return files; }
public static List<Path> staticCreateFiles(Path directory, int number) throws IOException { if (directory == null) { throw new NullPointerException("Path passed to createFiles cannot be null"); } FileAttribute<?>[] attrs = {}; Files.createDirectories(directory, attrs); assertTrue("Directory was not created", Files.exists(directory)); List<Path> files = new LinkedList<Path>(); for (int counter = 0 ; counter < number ; counter++) { Path newFile = directory.resolve("file" + counter + ".txt"); Files.createFile(newFile, attrs); assertTrue("File was not created", Files.exists(newFile)); files.add(newFile); } assertEquals("The number of files generated was not equal to the requested number", number, files.size()); // Check via another means final List<Path> visitorFiles = new LinkedList<Path>(); Files.walkFileTree(directory, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path path, BasicFileAttributes attributes) { if (path.toString().endsWith(".txt")) { visitorFiles.add(path); } return FileVisitResult.CONTINUE; } }); assertEquals("WalkFileTreeTest.staticCreateFiles() - The number of files created was not equal to the number seen using the FileVisitor. " + "FileVisitor found " + Arrays.toString(visitorFiles.toArray()) + " & we created " + Arrays.toString(files.toArray()) , number, visitorFiles.size()); return files; }
/** * Creates any necessary but nonexistent parent directories of the specified path. Note that if * this operation fails, it may have succeeded in creating some (but not all) of the necessary * parent directories. The parent directory is created with the given {@code attrs}. * * @throws IOException if an I/O error occurs, or if any necessary but nonexistent parent * directories of the specified file could not be created. */ public static void createParentDirectories( Path path, FileAttribute<?>... attrs) throws IOException { // Interestingly, unlike File.getCanonicalFile(), Path/Files provides no way of getting the // canonical (absolute, normalized, symlinks resolved, etc.) form of a path to a nonexistent // file. getCanonicalFile() can at least get the canonical form of the part of the path which // actually exists and then append the normalized remainder of the path to that. Path normalizedAbsolutePath = path.toAbsolutePath().normalize(); Path parent = normalizedAbsolutePath.getParent(); if (parent == null) { // The given directory is a filesystem root. All zero of its ancestors exist. This doesn't // mean that the root itself exists -- consider x:\ on a Windows machine without such a // drive -- or even that the caller can create it, but this method makes no such guarantees // even for non-root files. return; } // Check if the parent is a directory first because createDirectories will fail if the parent // exists and is a symlink to a directory... we'd like for this to succeed in that case. // (I'm kind of surprised that createDirectories would fail in that case; doesn't seem like // what you'd want to happen.) if (!Files.isDirectory(parent)) { Files.createDirectories(parent, attrs); if (!Files.isDirectory(parent)) { throw new IOException("Unable to create parent directories of " + path); } } }
/** * Java cannot load native libraries from jars so we need to expose the library * first by copying it to an external folder and then refreshing the Java library path. * * @param resourceName the name of the library resource to expose * @return whether the library was successfully exposed */ private boolean exposeNativeLibrary(String resourceName) { try { Path tempDir = Files.createTempDirectory("native-", new FileAttribute[0]); log.debug("Resource name: {}", resourceName); copyLibraryResources(tempDir, resourceName); refreshLibraryPath(tempDir); } catch (Throwable t) { log.warn("Unable to expose library {}", resourceName, t); return false; } return true; }
/** * Creates a temporary file in the given directory, or in in the * temporary directory if dir is {@code null}. */ static Path createTempFile(Path dir, String prefix, String suffix, FileAttribute<?>[] attrs) throws IOException { return create(dir, prefix, suffix, false, attrs); }
/** * Creates a temporary directory in the given directory, or in in the * temporary directory if dir is {@code null}. */ static Path createTempDirectory(Path dir, String prefix, FileAttribute<?>[] attrs) throws IOException { return create(dir, prefix, null, true, attrs); }
/** * Used by createDirectories to attempt to create a directory. A no-op * if the directory already exists. */ private static void createAndCheckIsDirectory(Path dir, FileAttribute<?>... attrs) throws IOException { try { createDirectory(dir, attrs); } catch (FileAlreadyExistsException x) { if (!isDirectory(dir, LinkOption.NOFOLLOW_LINKS)) throw x; } }
@Override public void createSymbolicLink(Path link, Path target, FileAttribute<?>... attrs) throws IOException { triggerEx(target, "createSymbolicLink"); Files.createSymbolicLink(unwrap(link), unwrap(target), attrs); }
@Override public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException { triggerEx(dir, "createDirectory"); Files.createDirectory(unwrap(dir), attrs); }
@Override public SeekableByteChannel newByteChannel(Path file, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException { triggerEx(file, "newByteChannel"); return Files.newByteChannel(unwrap(file), options, attrs); }
@Override public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException { if (options.contains(CustomOption.IGNORE)) { ignoreCount++; options.remove(CustomOption.IGNORE); } return super.newByteChannel(path, options, attrs); }
/** * Creates a temporary file in the given directory, or in the * temporary directory if dir is {@code null}. */ static Path createTempFile(Path dir, String prefix, String suffix, FileAttribute<?>[] attrs) throws IOException { return create(dir, prefix, suffix, false, attrs); }
/** * Creates a temporary directory in the given directory, or in the * temporary directory if dir is {@code null}. */ static Path createTempDirectory(Path dir, String prefix, FileAttribute<?>[] attrs) throws IOException { return create(dir, prefix, null, true, attrs); }
@Override public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException { Path delegate = theFileSystem.unwrap(dir); defaultProvider.createDirectory(delegate, attrs); }
@Override public SeekableByteChannel newByteChannel(Path file, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException { Path delegate = theFileSystem.unwrap(file); return defaultProvider.newByteChannel(delegate, options, attrs); }
public void testExtractToReadOnlyDir() throws IOException { Set<PosixFilePermission> perms = PosixFilePermissions.fromString("r-xr--r--"); FileAttribute<Set<PosixFilePermission>> atts = PosixFilePermissions.asFileAttribute(perms); Path tmp = Files.createTempDirectory(Paths.get("."), getClass().getName(), atts); jimage("extract", "--dir", tmp.toString(), getImagePath()) .assertFailure() .assertShowsError(); }
public static boolean mkdir( Path copy, FileAttribute... attrs ) { try { return Files.createDirectory( copy, attrs ) != null; } catch( FileAlreadyExistsException faee ) { return false; } catch( IOException e ) { throw new RuntimeException( e ); } }
public static boolean createNewFile( Path file, FileAttribute... attrs ) { try { return Files.createFile( file, attrs ) != null; } catch( FileAlreadyExistsException faee ) { return false; } catch( IOException e ) { throw new RuntimeException( e ); } }
@Override public SeekableByteChannel newByteChannel(Path file, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException { if (options.contains(StandardOpenOption.READ) && options.size() == 1) { Path delegate = theFileSystem.unwrap(file); options = Collections.singleton(StandardOpenOption.READ); return defaultProvider.newByteChannel(delegate, options, attrs); } throw new RuntimeException("not implemented"); }