use of java.nio.file.attribute.BasicFileAttributes in project buck by facebook.
the class ProvisioningProfileStore method fromSearchPath.
public static ProvisioningProfileStore fromSearchPath(final ProcessExecutor executor, final ImmutableList<String> readCommand, final Path searchPath) {
LOG.debug("Provisioning profile search path: " + searchPath);
return new ProvisioningProfileStore(Suppliers.memoize(() -> {
final ImmutableList.Builder<ProvisioningProfileMetadata> profilesBuilder = ImmutableList.builder();
try {
Files.walkFileTree(searchPath.toAbsolutePath(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (file.toString().endsWith(".mobileprovision")) {
try {
ProvisioningProfileMetadata profile = ProvisioningProfileMetadata.fromProvisioningProfilePath(executor, readCommand, file);
profilesBuilder.add(profile);
} catch (IOException | IllegalArgumentException e) {
LOG.error(e, "Ignoring invalid or malformed .mobileprovision file");
} catch (InterruptedException e) {
throw new IOException(e);
}
}
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
if (e.getCause() instanceof InterruptedException) {
LOG.error(e, "Interrupted while searching for mobileprovision files");
} else {
LOG.error(e, "Error while searching for mobileprovision files");
}
}
return profilesBuilder.build();
}));
}
use of java.nio.file.attribute.BasicFileAttributes in project buck by facebook.
the class MoreFiles method copyRecursively.
public static void copyRecursively(final Path fromPath, final Path toPath, final Function<Path, Path> transform, final Function<Path, Boolean> filter) throws IOException {
// Adapted from http://codingjunkie.net/java-7-copy-move/.
SimpleFileVisitor<Path> copyDirVisitor = new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
Path targetPath = toPath.resolve(fromPath.relativize(dir));
if (!Files.exists(targetPath)) {
Files.createDirectory(targetPath);
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (!filter.apply(file)) {
return FileVisitResult.CONTINUE;
}
Path destPath = toPath.resolve(fromPath.relativize(file));
Path transformedDestPath = transform.apply(destPath);
if (transformedDestPath != null) {
if (Files.isSymbolicLink(file)) {
Files.deleteIfExists(transformedDestPath);
Files.createSymbolicLink(transformedDestPath, Files.readSymbolicLink(file));
} else {
Files.copy(file, transformedDestPath, StandardCopyOption.REPLACE_EXISTING);
}
}
return FileVisitResult.CONTINUE;
}
};
Files.walkFileTree(fromPath, copyDirVisitor);
}
use of java.nio.file.attribute.BasicFileAttributes in project jimfs by google.
the class JimfsUnixLikeFileSystemTest method testCopy_withCopyAttributes.
@Test
public void testCopy_withCopyAttributes() throws IOException {
Path foo = path("/foo");
Files.createFile(foo);
Files.getFileAttributeView(foo, BasicFileAttributeView.class).setTimes(FileTime.fromMillis(100), FileTime.fromMillis(1000), FileTime.fromMillis(10000));
assertThat(Files.getAttribute(foo, "lastModifiedTime")).isEqualTo(FileTime.fromMillis(100));
UserPrincipal zero = fs.getUserPrincipalLookupService().lookupPrincipalByName("zero");
Files.setAttribute(foo, "owner:owner", zero);
Path bar = path("/bar");
Files.copy(foo, bar, COPY_ATTRIBUTES);
BasicFileAttributes attributes = Files.readAttributes(bar, BasicFileAttributes.class);
assertThat(attributes.lastModifiedTime()).isEqualTo(FileTime.fromMillis(100));
assertThat(attributes.lastAccessTime()).isEqualTo(FileTime.fromMillis(1000));
assertThat(attributes.creationTime()).isEqualTo(FileTime.fromMillis(10000));
assertThat(Files.getAttribute(bar, "owner:owner")).isEqualTo(zero);
Path baz = path("/baz");
Files.copy(foo, baz);
// test that attributes are not copied when COPY_ATTRIBUTES is not specified
attributes = Files.readAttributes(baz, BasicFileAttributes.class);
assertThat(attributes.lastModifiedTime()).isNotEqualTo(FileTime.fromMillis(100));
assertThat(attributes.lastAccessTime()).isNotEqualTo(FileTime.fromMillis(1000));
assertThat(attributes.creationTime()).isNotEqualTo(FileTime.fromMillis(10000));
assertThat(Files.getAttribute(baz, "owner:owner")).isNotEqualTo(zero);
}
use of java.nio.file.attribute.BasicFileAttributes in project jimfs by google.
the class BasicAttributeProviderTest method testAttributes.
@Test
public void testAttributes() {
BasicFileAttributes attrs = provider.readAttributes(file);
assertThat(attrs.fileKey()).isEqualTo(0);
assertThat(attrs.isDirectory()).isTrue();
assertThat(attrs.isRegularFile()).isFalse();
assertThat(attrs.creationTime()).isNotNull();
}
use of java.nio.file.attribute.BasicFileAttributes in project jimfs by google.
the class BasicAttributeProviderTest method testView.
@Test
public void testView() throws IOException {
BasicFileAttributeView view = provider.view(fileLookup(), NO_INHERITED_VIEWS);
assertThat(view).isNotNull();
assertThat(view.name()).isEqualTo("basic");
BasicFileAttributes attrs = view.readAttributes();
assertThat(attrs.fileKey()).isEqualTo(0);
FileTime time = attrs.creationTime();
assertThat(attrs.lastAccessTime()).isEqualTo(time);
assertThat(attrs.lastModifiedTime()).isEqualTo(time);
view.setTimes(null, null, null);
attrs = view.readAttributes();
assertThat(attrs.creationTime()).isEqualTo(time);
assertThat(attrs.lastAccessTime()).isEqualTo(time);
assertThat(attrs.lastModifiedTime()).isEqualTo(time);
view.setTimes(FileTime.fromMillis(0L), null, null);
attrs = view.readAttributes();
assertThat(attrs.creationTime()).isEqualTo(time);
assertThat(attrs.lastAccessTime()).isEqualTo(time);
assertThat(attrs.lastModifiedTime()).isEqualTo(FileTime.fromMillis(0L));
}
Aggregations