use of java.nio.file.attribute.DosFileAttributes in project syncany by syncany.
the class LimitedDosFileAttributesTest method testFileDosAttrs.
@Test
public void testFileDosAttrs() throws Exception {
DosFileAttributes dosAttrsRHAS = FileUtil.dosAttrsFromString("rhas");
assertTrue(dosAttrsRHAS.isReadOnly());
assertTrue(dosAttrsRHAS.isHidden());
assertTrue(dosAttrsRHAS.isArchive());
assertTrue(dosAttrsRHAS.isSystem());
DosFileAttributes dosAttrsRHA = FileUtil.dosAttrsFromString("rha-");
assertTrue(dosAttrsRHA.isReadOnly());
assertTrue(dosAttrsRHA.isHidden());
assertTrue(dosAttrsRHA.isArchive());
assertFalse(dosAttrsRHA.isSystem());
DosFileAttributes dosAttrsRH = FileUtil.dosAttrsFromString("rh--");
assertTrue(dosAttrsRH.isReadOnly());
assertTrue(dosAttrsRH.isHidden());
assertFalse(dosAttrsRH.isArchive());
assertFalse(dosAttrsRH.isSystem());
DosFileAttributes dosAttrsR = FileUtil.dosAttrsFromString("r---");
assertTrue(dosAttrsR.isReadOnly());
assertFalse(dosAttrsR.isHidden());
assertFalse(dosAttrsR.isArchive());
assertFalse(dosAttrsR.isSystem());
DosFileAttributes dosAttrsNone = FileUtil.dosAttrsFromString("----");
assertFalse(dosAttrsNone.isReadOnly());
assertFalse(dosAttrsNone.isHidden());
assertFalse(dosAttrsNone.isArchive());
assertFalse(dosAttrsNone.isSystem());
DosFileAttributes dosAttrsH = FileUtil.dosAttrsFromString("-h--");
assertFalse(dosAttrsH.isReadOnly());
assertTrue(dosAttrsH.isHidden());
assertFalse(dosAttrsH.isArchive());
assertFalse(dosAttrsH.isSystem());
DosFileAttributes dosAttrsCorrect = FileUtil.dosAttrsFromString("NONO");
assertFalse(dosAttrsCorrect.isReadOnly());
assertFalse(dosAttrsCorrect.isHidden());
assertFalse(dosAttrsCorrect.isArchive());
assertFalse(dosAttrsCorrect.isSystem());
// Can't do all ...
}
use of java.nio.file.attribute.DosFileAttributes in project syncany by syncany.
the class FileSystemAction method setFileAttributes.
protected void setFileAttributes(FileVersion reconstructedFileVersion, File reconstructedFilesAtFinalLocation) throws IOException {
if (EnvironmentUtil.isWindows()) {
if (reconstructedFileVersion.getDosAttributes() != null) {
logger.log(Level.INFO, " - Setting DOS attributes: " + reconstructedFileVersion.getDosAttributes() + " ...");
DosFileAttributes dosAttrs = FileUtil.dosAttrsFromString(reconstructedFileVersion.getDosAttributes());
Path filePath = Paths.get(reconstructedFilesAtFinalLocation.getAbsolutePath());
try {
Files.setAttribute(filePath, "dos:readonly", dosAttrs.isReadOnly());
Files.setAttribute(filePath, "dos:hidden", dosAttrs.isHidden());
Files.setAttribute(filePath, "dos:archive", dosAttrs.isArchive());
Files.setAttribute(filePath, "dos:system", dosAttrs.isSystem());
} catch (IOException e) {
logger.log(Level.WARNING, " - WARNING: Cannot set file attributes for " + filePath, e);
}
}
} else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
if (reconstructedFileVersion.getPosixPermissions() != null) {
logger.log(Level.INFO, " - Setting POSIX permissions: " + reconstructedFileVersion.getPosixPermissions() + " ...");
Set<PosixFilePermission> posixPerms = PosixFilePermissions.fromString(reconstructedFileVersion.getPosixPermissions());
Path filePath = Paths.get(reconstructedFilesAtFinalLocation.getAbsolutePath());
try {
Files.setPosixFilePermissions(filePath, posixPerms);
} catch (IOException e) {
logger.log(Level.WARNING, " - WARNING: Cannot set file permissions for " + filePath, e);
}
}
}
}
use of java.nio.file.attribute.DosFileAttributes in project syncany by syncany.
the class FileVersionComparatorTest method testCaptureFilePropertiesFromFile.
@Test
public void testCaptureFilePropertiesFromFile() throws Exception {
// Setup
Config config = TestConfigUtil.createTestLocalConfig();
FileVersionComparator versionComparator = new FileVersionComparator(config.getLocalDir(), config.getChunker().getChecksumAlgorithm());
// Create file
File somefile = new File(config.getLocalDir() + "/somefile");
Path somefilePath = Paths.get(somefile.getAbsolutePath());
TestFileUtil.createRandomFile(somefile, 100 * 1024);
somefile.setLastModified(1382196000);
if (EnvironmentUtil.isWindows()) {
Files.setAttribute(somefilePath, "dos:archive", false);
Files.setAttribute(somefilePath, "dos:hidden", false);
Files.setAttribute(somefilePath, "dos:readonly", false);
Files.setAttribute(somefilePath, "dos:system", false);
} else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
Files.setPosixFilePermissions(somefilePath, PosixFilePermissions.fromString("rw-rw-r-x"));
}
// Run
FileProperties fileProperties = versionComparator.captureFileProperties(somefile, null, true);
// Test
assertNotNull(fileProperties.getChecksum());
assertEquals(1382196000, fileProperties.getLastModified());
assertEquals("somefile", fileProperties.getRelativePath());
assertEquals(100 * 1024, fileProperties.getSize());
assertNull(fileProperties.getLinkTarget());
assertTrue(fileProperties.exists());
assertEquals(FileType.FILE, fileProperties.getType());
if (EnvironmentUtil.isWindows()) {
DosFileAttributes dosFileAttributes = FileUtil.dosAttrsFromString(fileProperties.getDosAttributes());
assertFalse(dosFileAttributes.isArchive());
assertFalse(dosFileAttributes.isHidden());
assertFalse(dosFileAttributes.isReadOnly());
assertFalse(dosFileAttributes.isSystem());
assertNull(fileProperties.getPosixPermissions());
} else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
assertEquals("rw-rw-r-x", fileProperties.getPosixPermissions());
assertNull(fileProperties.getDosAttributes());
}
// Tear down
TestConfigUtil.deleteTestLocalConfigAndData(config);
}
use of java.nio.file.attribute.DosFileAttributes in project syncany by syncany.
the class FileVersionComparatorTest method testCaptureFilePropertiesFromFileVersion.
@Test
public void testCaptureFilePropertiesFromFileVersion() throws Exception {
// Setup
Config config = TestConfigUtil.createTestLocalConfig();
FileVersionComparator versionComparator = new FileVersionComparator(config.getLocalDir(), config.getChunker().getChecksumAlgorithm());
FileVersion fileVersion = new FileVersion();
fileVersion.setVersion(3L);
fileVersion.setChecksum(new FileChecksum(new byte[] { 0x11, 0x22, 0x33 }));
fileVersion.setLastModified(new Date(123456789));
fileVersion.setPath("folder/file");
fileVersion.setSize(999 * 1024L);
fileVersion.setLinkTarget(null);
fileVersion.setStatus(FileStatus.CHANGED);
fileVersion.setType(FileType.FILE);
if (EnvironmentUtil.isWindows()) {
fileVersion.setDosAttributes("rha-");
} else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
fileVersion.setPosixPermissions("rw-rw-r-x");
}
// Run
FileProperties fileProperties = versionComparator.captureFileProperties(fileVersion);
// Test
assertEquals(new FileChecksum(new byte[] { 0x11, 0x22, 0x33 }), fileProperties.getChecksum());
assertEquals(123456789, fileProperties.getLastModified());
assertEquals("folder/file", fileProperties.getRelativePath());
assertEquals(999 * 1024, fileProperties.getSize());
assertNull(fileProperties.getLinkTarget());
assertTrue(fileProperties.exists());
assertEquals(FileType.FILE, fileProperties.getType());
if (EnvironmentUtil.isWindows()) {
DosFileAttributes dosFileAttributes = FileUtil.dosAttrsFromString(fileProperties.getDosAttributes());
assertTrue(dosFileAttributes.isArchive());
assertTrue(dosFileAttributes.isHidden());
assertTrue(dosFileAttributes.isReadOnly());
assertFalse(dosFileAttributes.isSystem());
assertNull(fileProperties.getPosixPermissions());
} else if (EnvironmentUtil.isUnixLikeOperatingSystem()) {
assertEquals("rw-rw-r-x", fileProperties.getPosixPermissions());
assertNull(fileProperties.getDosAttributes());
}
// Tear down
TestConfigUtil.deleteTestLocalConfigAndData(config);
}
use of java.nio.file.attribute.DosFileAttributes in project jimfs by google.
the class DosAttributeProviderTest method testView.
@Test
public void testView() throws IOException {
DosFileAttributeView view = provider.view(fileLookup(), ImmutableMap.<String, FileAttributeView>of("basic", new BasicAttributeProvider().view(fileLookup(), NO_INHERITED_VIEWS)));
assertNotNull(view);
assertThat(view.name()).isEqualTo("dos");
DosFileAttributes attrs = view.readAttributes();
assertThat(attrs.isHidden()).isFalse();
assertThat(attrs.isArchive()).isFalse();
assertThat(attrs.isReadOnly()).isFalse();
assertThat(attrs.isSystem()).isFalse();
view.setArchive(true);
view.setReadOnly(true);
view.setHidden(true);
view.setSystem(false);
assertThat(attrs.isHidden()).isFalse();
assertThat(attrs.isArchive()).isFalse();
assertThat(attrs.isReadOnly()).isFalse();
attrs = view.readAttributes();
assertThat(attrs.isHidden()).isTrue();
assertThat(attrs.isArchive()).isTrue();
assertThat(attrs.isReadOnly()).isTrue();
assertThat(attrs.isSystem()).isFalse();
view.setTimes(FileTime.fromMillis(0L), null, null);
assertThat(view.readAttributes().lastModifiedTime()).isEqualTo(FileTime.fromMillis(0L));
}
Aggregations