-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
5 changed files
with
154 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
onedrive/src/main/java/ch/cyberduck/core/onedrive/OneDriveTimestampFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package ch.cyberduck.core.onedrive; | ||
|
||
/* | ||
* Copyright (c) 2002-2018 iterate GmbH. All rights reserved. | ||
* https://cyberduck.io/ | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*/ | ||
|
||
import ch.cyberduck.core.DefaultIOExceptionMappingService; | ||
import ch.cyberduck.core.Local; | ||
import ch.cyberduck.core.Path; | ||
import ch.cyberduck.core.exception.BackgroundException; | ||
import ch.cyberduck.core.features.Timestamp; | ||
import ch.cyberduck.core.shared.DefaultTimestampFeature; | ||
|
||
import org.nuxeo.onedrive.client.OneDriveAPIException; | ||
import org.nuxeo.onedrive.client.OneDriveFile; | ||
import org.nuxeo.onedrive.client.OneDriveItem; | ||
import org.nuxeo.onedrive.client.OneDrivePatchOperation; | ||
import org.nuxeo.onedrive.client.facets.FileSystemInfoFacet; | ||
|
||
import java.io.IOException; | ||
import java.time.Instant; | ||
import java.time.OffsetDateTime; | ||
import java.time.ZoneId; | ||
import java.time.ZoneOffset; | ||
import java.time.ZonedDateTime; | ||
|
||
import com.sun.scenario.effect.Offset; | ||
|
||
public class OneDriveTimestampFeature extends DefaultTimestampFeature { | ||
private final OneDriveSession session; | ||
|
||
public OneDriveTimestampFeature(OneDriveSession session) { | ||
this.session = session; | ||
} | ||
|
||
@Override | ||
public void setTimestamp(final Path file, final Long modified) throws BackgroundException { | ||
final OneDrivePatchOperation patchOperation = new OneDrivePatchOperation(); | ||
final FileSystemInfoFacet facet = new FileSystemInfoFacet(); | ||
facet.setLastModifiedDateTime(Instant.ofEpochMilli(modified).atOffset(ZoneOffset.UTC)); | ||
patchOperation.facet("fileSystemInfo", facet); | ||
|
||
try { | ||
session.toFile(file).patch(patchOperation); | ||
} | ||
catch(OneDriveAPIException e) { | ||
throw new OneDriveExceptionMappingService().map("Cannot patch timestamp {0}", e, file); | ||
} | ||
catch(IOException e) { | ||
throw new DefaultIOExceptionMappingService().map("Cannot patch timestamp {0}", e, file); | ||
} | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
onedrive/src/test/java/ch/cyberduck/core/onedrive/OneDriveTimestampFeatureTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package ch.cyberduck.core.onedrive; | ||
|
||
/* | ||
* Copyright (c) 2002-2018 iterate GmbH. All rights reserved. | ||
* https://cyberduck.io/ | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
*/ | ||
|
||
import ch.cyberduck.core.AlphanumericRandomStringService; | ||
import ch.cyberduck.core.DisabledLoginCallback; | ||
import ch.cyberduck.core.Path; | ||
import ch.cyberduck.core.features.AttributesFinder; | ||
import ch.cyberduck.core.features.Delete; | ||
import ch.cyberduck.core.features.Directory; | ||
import ch.cyberduck.core.features.Timestamp; | ||
import ch.cyberduck.core.features.Touch; | ||
import ch.cyberduck.core.transfer.TransferStatus; | ||
import ch.cyberduck.test.IntegrationTest; | ||
|
||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
|
||
import java.time.Instant; | ||
import java.util.Collections; | ||
import java.util.EnumSet; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
@Category(IntegrationTest.class) | ||
public class OneDriveTimestampFeatureTest extends AbstractOneDriveTest { | ||
@Test | ||
public void testSetTimestamp() throws Exception { | ||
final Touch touch = new OneDriveTouchFeature(session); | ||
final Delete delete = new OneDriveDeleteFeature(session); | ||
final AttributesFinder attributesFinder = new OneDriveAttributesFinderFeature(session); | ||
final Timestamp timestamp = new OneDriveTimestampFeature(session); | ||
|
||
final Path drive = new OneDriveHomeFinderFeature(session).find(); | ||
final Path file = new Path(drive, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); | ||
touch.touch(file, new TransferStatus().withMime("x-application/cyberduck")); | ||
assertNotNull(attributesFinder.find(file)); | ||
|
||
final long modified = Instant.now().minusSeconds(5 * 24 * 60 * 60).toEpochMilli(); | ||
timestamp.setTimestamp(file, modified); | ||
assertEquals(modified, attributesFinder.find(file).getModificationDate()); | ||
|
||
delete.delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback()); | ||
} | ||
|
||
@Test | ||
public void testSetTimestampDirectory() throws Exception { | ||
final Directory directory = new OneDriveDirectoryFeature(session); | ||
final Delete delete = new OneDriveDeleteFeature(session); | ||
final AttributesFinder attributesFinder = new OneDriveAttributesFinderFeature(session); | ||
final Timestamp timestamp = new OneDriveTimestampFeature(session); | ||
|
||
final Path drive = new OneDriveHomeFinderFeature(session).find(); | ||
final Path test = new Path(drive, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); | ||
directory.mkdir(test, null, null); | ||
assertNotNull(attributesFinder.find(test)); | ||
|
||
final long modified = Instant.now().minusSeconds(5 * 24 * 60 * 60).toEpochMilli(); | ||
timestamp.setTimestamp(test, modified); | ||
assertEquals(modified, attributesFinder.find(test).getModificationDate()); | ||
|
||
delete.delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); | ||
} | ||
} |