Search in sources :

Example 1 with DosFileAttributes

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 ...
}
Also used : LimitedDosFileAttributes(org.syncany.util.LimitedDosFileAttributes) DosFileAttributes(java.nio.file.attribute.DosFileAttributes) Test(org.junit.Test)

Example 2 with DosFileAttributes

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);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) NormalizedPath(org.syncany.util.NormalizedPath) Set(java.util.Set) DosFileAttributes(java.nio.file.attribute.DosFileAttributes) IOException(java.io.IOException)

Example 3 with DosFileAttributes

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);
}
Also used : Path(java.nio.file.Path) FileProperties(org.syncany.database.FileVersionComparator.FileProperties) Config(org.syncany.config.Config) DosFileAttributes(java.nio.file.attribute.DosFileAttributes) FileVersionComparator(org.syncany.database.FileVersionComparator) File(java.io.File) Test(org.junit.Test)

Example 4 with DosFileAttributes

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);
}
Also used : FileProperties(org.syncany.database.FileVersionComparator.FileProperties) Config(org.syncany.config.Config) DosFileAttributes(java.nio.file.attribute.DosFileAttributes) FileVersion(org.syncany.database.FileVersion) FileVersionComparator(org.syncany.database.FileVersionComparator) FileChecksum(org.syncany.database.FileContent.FileChecksum) Date(java.util.Date) Test(org.junit.Test)

Example 5 with DosFileAttributes

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));
}
Also used : DosFileAttributeView(java.nio.file.attribute.DosFileAttributeView) DosFileAttributes(java.nio.file.attribute.DosFileAttributes) Test(org.junit.Test)

Aggregations

DosFileAttributes (java.nio.file.attribute.DosFileAttributes)10 Test (org.junit.Test)6 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 File (java.io.File)3 Config (org.syncany.config.Config)2 FileChecksum (org.syncany.database.FileContent.FileChecksum)2 FileVersionComparator (org.syncany.database.FileVersionComparator)2 FileProperties (org.syncany.database.FileVersionComparator.FileProperties)2 LimitedDosFileAttributes (org.syncany.util.LimitedDosFileAttributes)2 FileSystemOperationException (com.axway.ats.common.filesystem.FileSystemOperationException)1 FileStatus (com.google.devtools.build.lib.vfs.FileStatus)1 FileNotFoundException (java.io.FileNotFoundException)1 RandomAccessFile (java.io.RandomAccessFile)1 InvalidPathException (java.nio.file.InvalidPathException)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 DosFileAttributeView (java.nio.file.attribute.DosFileAttributeView)1 PosixFileAttributes (java.nio.file.attribute.PosixFileAttributes)1 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1