Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Jan 29, 2018
2 parents acd55ca + 4ec2985 commit 0b96e9f
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 17 deletions.
2 changes: 1 addition & 1 deletion onedrive/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<dependency>
<groupId>ch.iterate.onedrive</groupId>
<artifactId>onedrive-java-client</artifactId>
<version>2.0.10</version>
<version>2.0.12</version>
</dependency>
<dependency>
<groupId>ch.cyberduck</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,13 @@ protected PathAttributes convert(final OneDriveItem.Metadata metadata) {
catch(URISyntaxException e) {
log.warn(String.format("Cannot set link. Web URL returned %s", metadata.getWebUrl()), e);
}
attributes.setModificationDate(metadata.getLastModifiedDateTime().toInstant().toEpochMilli());
attributes.setCreationDate(metadata.getCreatedDateTime().toInstant().toEpochMilli());
if (null != metadata.getFileSystemInfo()) {
attributes.setModificationDate(metadata.getFileSystemInfo().getLastModifiedDateTime().toInstant().toEpochMilli());
attributes.setCreationDate(metadata.getFileSystemInfo().getCreatedDateTime().toInstant().toEpochMilli());
} else {
attributes.setModificationDate(metadata.getLastModifiedDateTime().toInstant().toEpochMilli());
attributes.setCreationDate(metadata.getCreatedDateTime().toInstant().toEpochMilli());
}
return attributes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,7 @@
import ch.cyberduck.core.URIEncoder;
import ch.cyberduck.core.UrlProvider;
import ch.cyberduck.core.exception.BackgroundException;
import ch.cyberduck.core.features.AttributesFinder;
import ch.cyberduck.core.features.Copy;
import ch.cyberduck.core.features.Delete;
import ch.cyberduck.core.features.Directory;
import ch.cyberduck.core.features.Find;
import ch.cyberduck.core.features.Home;
import ch.cyberduck.core.features.Move;
import ch.cyberduck.core.features.MultipartWrite;
import ch.cyberduck.core.features.PromptUrlProvider;
import ch.cyberduck.core.features.Quota;
import ch.cyberduck.core.features.Read;
import ch.cyberduck.core.features.Search;
import ch.cyberduck.core.features.Touch;
import ch.cyberduck.core.features.Write;
import ch.cyberduck.core.features.*;
import ch.cyberduck.core.http.HttpSession;
import ch.cyberduck.core.oauth.OAuth2ErrorResponseInterceptor;
import ch.cyberduck.core.oauth.OAuth2RequestInterceptor;
Expand Down Expand Up @@ -208,6 +195,9 @@ public <T> T _getFeature(final Class<T> type) {
if(type == Search.class) {
return (T) new OneDriveSearchFeature(this);
}
if(type == Timestamp.class) {
return (T) new OneDriveTimestampFeature(this);
}
return super._getFeature(type);
}
}
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);
}
}
}
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());
}
}

0 comments on commit 0b96e9f

Please sign in to comment.