private FileStatus toFileStatus(File metadata) { return new FileStatus(metadata.getSize() == null ? 0L : metadata.getSize(), FOLDER_MIME_TYPE.equals(metadata.getMimeType()), -1, -1, metadata.getModifiedTime().getValue(), new Path(metadata.getId())); }
new DigitalDocumentWrapper( new DtpDigitalDocument( file.getName(), file.getModifiedTime().toStringRfc3339(), newMimeType), file.getMimeType(), file.getId()));
private void createLocalDir(File newDirectory, SyncItem syncItem, com.google.api.services.drive.model.File remoteFile) throws IOException { LOGGER.log(Level.FINE, "Creating local directory '" + syncItem.getPath() + "'."); Path newLocalDir = fileSystemAdapter.createDirectory(newDirectory); DateTime lastModifiedDateTime = remoteFile.getModifiedTime(); fileSystemAdapter.setLastModifiedTime(newLocalDir.toFile(), lastModifiedDateTime.getValue()); syncItem.setLocalFile(Optional.of(newLocalDir.toFile())); }
private FileStatus toFileStatus(File metadata) { return new FileStatus(metadata.getSize() == null ? 0L : metadata.getSize(), FOLDER_MIME_TYPE.equals(metadata.getMimeType()), -1, -1, metadata.getModifiedTime().getValue(), new Path(metadata.getId())); }
copyStreamToFile(inputStream, newFile); syncItem.setLocalFile(Optional.of(newFile)); setLastModifiedTime(newFile, remoteFile.getModifiedTime().getValue()); } else { LOGGER.log(Level.WARNING, "Cannot create file '" + syncItem.getPath() + "' because local file is not present."); copyStreamToFile(inputStream, newFile); syncItem.setLocalFile(Optional.of(newFile)); setLastModifiedTime(newFile, remoteFile.getModifiedTime().getValue());
if(f.getModifiedTime() != null) { attributes.setModificationDate(f.getModifiedTime().getValue());
private GFile create(File file) { GFile newFile = new GFile(file.getName() != null ? file.getName() : file.getOriginalFilename()); newFile.setId(file.getId()); newFile.setLastModified(file.getModifiedTime() != null ? file.getModifiedTime().getValue() : 0); newFile.setDirectory(GFile.MIME_TYPE.GOOGLE_FOLDER.getValue().equals(file.getMimeType())); newFile.setSize(file.getSize() != null ? file.getSize() : 0); // null for directories newFile.setMimeType(file.getMimeType()); newFile.setMd5Checksum(file.getMd5Checksum()); if (file.getParents() != null) { Set<String> newParents = new HashSet<>(); for (String newParent : file.getParents()) { newParents.add(newParent.equals(ROOT_FOLDER_ID) ? "root" : newParent); } newFile.setParents(newParents); } else { // does this happen? newFile.setParents(Collections.singleton("root")); } newFile.setTrashed(file.getTrashed() != null && file.getTrashed()); return newFile; }
BasicFileAttributes attr = Files.readAttributes(localFile.toPath(), BasicFileAttributes.class); FileTime modifiedDateLocal = attr.lastModifiedTime(); DateTime modifiedDateRemote = remoteChild.getModifiedTime(); long sizeLocal = attr.size(); Long sizeRemote = remoteChild.getSize() == null ? 0L : remoteChild.getSize();
private void performChecksumCheck(File file, SyncItem syncItem, com.google.api.services.drive.model.File remoteFile, boolean updateMetadata) { String remoteFileMd5Checksum = remoteFile.getMd5Checksum(); String localFileMd5Checksum = computeMd5Checksum(file); if (remoteFileMd5Checksum.equals(localFileMd5Checksum)) { syncItem.setLocalFile(Optional.of(file)); if (!updateMetadata) { LOGGER.log(Level.FINE, "Not downloading file '" + syncItem.getPath() + "' because MD5 checksums are equal (local: " + localFileMd5Checksum + ", remote: " + remoteFileMd5Checksum + ")."); ReportFactory.getInstance(options).log(new ReportEntry(syncItem.getPath(), ReportEntry.Status.Synchronized, ReportEntry.Action.Unchanged)); } else { try { fileSystemAdapter.setLastModifiedTime(file, remoteFile.getModifiedTime().getValue()); ReportFactory.getInstance(options).log(new ReportEntry(syncItem.getPath(), ReportEntry.Status.Synchronized, ReportEntry.Action.UpdatedMetadata)); } catch (Exception e) { LOGGER.log(Level.WARNING, "Could not update last modification date of local file '" + file.getAbsolutePath() + "':" + e.getMessage(), e); ReportFactory.getInstance(options).log(new ReportEntry(syncItem.getPath(), ReportEntry.Status.Error, ReportEntry.Action.Skipped, e.getMessage())); } } } else { LOGGER.log(Level.FINE, "Downloading file '" + syncItem.getPath() + "' because MD5 checksums are not equal (local: " + localFileMd5Checksum + ", remote: " + remoteFileMd5Checksum + ")."); try { InputStream stream = googleDriveAdapter.downloadFile(syncItem); fileSystemAdapter.storeFile(stream, syncItem); ReportFactory.getInstance(options).log(new ReportEntry(syncItem.getPath(), ReportEntry.Status.Synchronized, ReportEntry.Action.Updated)); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Failed to store file '" + syncItem.getPath() + "': " + e.getMessage()); ReportFactory.getInstance(options).log(new ReportEntry(syncItem.getPath(), ReportEntry.Status.Error, ReportEntry.Action.Skipped)); } } } });
private IndexedRecord convertSearchResultToIndexedRecord(File file) { // Main record IndexedRecord main = new GenericData.Record(schema); main.put(0, file.getId()); main.put(1, file.getName()); main.put(2, file.getMimeType()); main.put(3, file.getModifiedTime().getValue()); main.put(4, file.getSize()); main.put(5, file.getKind()); main.put(6, file.getTrashed()); main.put(7, file.getParents().toString()); // TODO This should be a List<String> main.put(8, file.getWebViewLink()); return main; }
final File s = o.latestStonky(); LOGGER.debug("Making a backup of the existing spreadsheet."); final Instant lastModified = Instant.EPOCH.plus(Duration.ofMillis(s.getModifiedTime().getValue())); final LocalDate d = lastModified.atZone(Defaults.ZONE_ID).toLocalDate(); if (d.isBefore(DateUtil.localNow().toLocalDate())) {
private IndexedRecord convertSearchResultToIndexedRecord(File file) { // Main record IndexedRecord main = new GenericData.Record(schema); main.put(0, file.getId()); main.put(1, file.getName()); main.put(2, file.getMimeType()); main.put(3, file.getModifiedTime().getValue()); main.put(4, file.getSize()); main.put(5, file.getKind()); main.put(6, file.getTrashed()); main.put(7, file.getParents().toString()); // TODO This should be a List<String> main.put(8, file.getWebViewLink()); return main; }
final File s = o.latestStonky(); LOGGER.debug("Making a backup of the existing spreadsheet."); final Instant lastModified = Instant.EPOCH.plus(Duration.ofMillis(s.getModifiedTime().getValue())); final LocalDate d = lastModified.atZone(Defaults.ZONE_ID).toLocalDate(); if (d.isBefore(DateUtil.localNow().toLocalDate())) {
performChecksumCheck(file, syncItem, remoteFile, false); } else { DateTime remoteFileModifiedDate = remoteFile.getModifiedTime(); try { BasicFileAttributes attr = fileSystemAdapter.readAttributes(file);