use of java.nio.file.LinkOption in project buck by facebook.
the class DefaultJavaLibraryTest method testJavaLibaryThrowsIfResourceIsDirectory.
@Test
public void testJavaLibaryThrowsIfResourceIsDirectory() throws Exception {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem() {
@Override
public boolean isDirectory(Path path, LinkOption... linkOptionsk) {
return true;
}
};
try {
JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//library:code")).addResource(new FakeSourcePath("library")).build(ruleResolver, filesystem);
fail("An exception should have been thrown because a directory was passed as a resource.");
} catch (HumanReadableException e) {
assertTrue(e.getHumanReadableErrorMessage().contains("a directory is not a valid input"));
}
}
use of java.nio.file.LinkOption in project jdk8u_jdk by JetBrains.
the class CopyAndMove method copyAndVerify.
// copy source to target with verification
static void copyAndVerify(Path source, Path target, CopyOption... options) throws IOException {
Path result = copy(source, target, options);
assertTrue(result == target);
// get attributes of source and target file to verify copy
boolean followLinks = true;
LinkOption[] linkOptions = new LinkOption[0];
boolean copyAttributes = false;
for (CopyOption opt : options) {
if (opt == NOFOLLOW_LINKS) {
followLinks = false;
linkOptions = new LinkOption[] { NOFOLLOW_LINKS };
}
if (opt == COPY_ATTRIBUTES)
copyAttributes = true;
}
BasicFileAttributes basicAttributes = readAttributes(source, BasicFileAttributes.class, linkOptions);
// check hash if regular file
if (basicAttributes.isRegularFile())
assertTrue(computeHash(source) == computeHash(target));
// check link target if symbolic link
if (basicAttributes.isSymbolicLink())
assert (readSymbolicLink(source).equals(readSymbolicLink(target)));
// check that attributes are copied
if (copyAttributes && followLinks) {
checkBasicAttributes(basicAttributes, readAttributes(source, BasicFileAttributes.class, linkOptions));
// verify other attributes when same provider
if (source.getFileSystem().provider() == target.getFileSystem().provider()) {
// check POSIX attributes are copied
String os = System.getProperty("os.name");
if ((os.equals("SunOS") || os.equals("Linux")) && testPosixAttributes) {
checkPosixAttributes(readAttributes(source, PosixFileAttributes.class, linkOptions), readAttributes(target, PosixFileAttributes.class, linkOptions));
}
// check DOS attributes are copied
if (os.startsWith("Windows")) {
checkDosAttributes(readAttributes(source, DosFileAttributes.class, linkOptions), readAttributes(target, DosFileAttributes.class, linkOptions));
}
// check named attributes are copied
if (followLinks && getFileStore(source).supportsFileAttributeView("xattr") && getFileStore(target).supportsFileAttributeView("xattr")) {
checkUserDefinedFileAttributes(readUserDefinedFileAttributes(source), readUserDefinedFileAttributes(target));
}
}
}
}
use of java.nio.file.LinkOption in project cryptofs by cryptomator.
the class CryptoFileSystemProviderTest method testReadAttributesWithNameDelegatesToFileSystem.
@Test
public void testReadAttributesWithNameDelegatesToFileSystem() throws IOException {
@SuppressWarnings("unchecked") Map<String, Object> attributes = mock(Map.class);
LinkOption option = LinkOption.NOFOLLOW_LINKS;
String name = "foobar";
when(cryptoFileSystem.readAttributes(cryptoPath, name, option)).thenReturn(attributes);
Map<String, Object> result = inTest.readAttributes(cryptoPath, name, option);
assertThat(result, is(attributes));
}
use of java.nio.file.LinkOption in project cryptofs by cryptomator.
the class CryptoFileSystemProviderTest method testGetFileAttributeViewDelegatesToFileSystem.
@Test
public void testGetFileAttributeViewDelegatesToFileSystem() {
FileAttributeView view = mock(FileAttributeView.class);
LinkOption option = LinkOption.NOFOLLOW_LINKS;
when(cryptoFileSystem.getFileAttributeView(cryptoPath, FileAttributeView.class, option)).thenReturn(view);
FileAttributeView result = inTest.getFileAttributeView(cryptoPath, FileAttributeView.class, option);
assertThat(result, is(view));
}
use of java.nio.file.LinkOption in project cryptofs by cryptomator.
the class CryptoFileSystemProviderTest method testReadAttributesWithTypeDelegatesToFileSystem.
@Test
public void testReadAttributesWithTypeDelegatesToFileSystem() throws IOException {
BasicFileAttributes attributes = mock(BasicFileAttributes.class);
LinkOption option = LinkOption.NOFOLLOW_LINKS;
when(cryptoFileSystem.readAttributes(cryptoPath, BasicFileAttributes.class, option)).thenReturn(attributes);
BasicFileAttributes result = inTest.readAttributes(cryptoPath, BasicFileAttributes.class, option);
assertThat(result, is(attributes));
}
Aggregations