From c6916126ee7a6d18d2cfcca74d7a974fd81d1d3b Mon Sep 17 00:00:00 2001 From: Boris Petrov Date: Wed, 5 Jan 2022 18:03:35 +0200 Subject: [PATCH 1/3] Fix not populating file data from Google Drive --- .../java/com/sshtools/vfs/googledrive/GDriveFileObject.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vfs-googledrive/src/main/java/com/sshtools/vfs/googledrive/GDriveFileObject.java b/vfs-googledrive/src/main/java/com/sshtools/vfs/googledrive/GDriveFileObject.java index fa7b815..df20be5 100644 --- a/vfs-googledrive/src/main/java/com/sshtools/vfs/googledrive/GDriveFileObject.java +++ b/vfs-googledrive/src/main/java/com/sshtools/vfs/googledrive/GDriveFileObject.java @@ -80,12 +80,13 @@ protected void doAttach() throws IOException { } } com.google.api.services.drive.Drive.Files.List request = null; + // TODO: figure out which fields are needed and add only those instead of using `*` below if (path.equals("/")) { /* Root */ - request = drive.files().list().setQ("'root' in parents"); + request = drive.files().list().setFields("*").setQ("'root' in parents"); } else if (file != null && "application/vnd.google-apps.folder".equals(file.getMimeType())) { /* If this is known to be a directory, list the files in it */ - request = drive.files().list().setQ(String.format("'%s' in parents", file.getId())); + request = drive.files().list().setFields("*").setQ(String.format("'%s' in parents", file.getId())); } if (request != null) { children = new ArrayList(); From 6c13da1e18d3ffefd6f774bb8d475f3259cd9afe Mon Sep 17 00:00:00 2001 From: Boris Petrov Date: Wed, 5 Jan 2022 18:05:14 +0200 Subject: [PATCH 2/3] Fix not refreshing a file after it is changed --- .../java/com/sshtools/vfs/googledrive/GDriveFileObject.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vfs-googledrive/src/main/java/com/sshtools/vfs/googledrive/GDriveFileObject.java b/vfs-googledrive/src/main/java/com/sshtools/vfs/googledrive/GDriveFileObject.java index df20be5..6f961cc 100644 --- a/vfs-googledrive/src/main/java/com/sshtools/vfs/googledrive/GDriveFileObject.java +++ b/vfs-googledrive/src/main/java/com/sshtools/vfs/googledrive/GDriveFileObject.java @@ -208,6 +208,11 @@ private long processTime(DateTime dateTime) { return dateTime == null ? 0 : dateTime.getValue(); } + @Override + protected void onChange() throws IOException { + this.refresh(); + } + @Override protected long doGetContentSize() throws Exception { return file == null ? 0 : (file.getSize() == null ? 0 : file.getSize().longValue()); From d9bb46b6557dc329bc874aba68e2efdb0cd38c51 Mon Sep 17 00:00:00 2001 From: Boris Petrov Date: Wed, 5 Jan 2022 18:08:11 +0200 Subject: [PATCH 3/3] Workaround issue with Google Drive files being unreadable after creation --- .../java/com/sshtools/vfs/googledrive/GDriveFileObject.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/vfs-googledrive/src/main/java/com/sshtools/vfs/googledrive/GDriveFileObject.java b/vfs-googledrive/src/main/java/com/sshtools/vfs/googledrive/GDriveFileObject.java index 6f961cc..565cf1b 100644 --- a/vfs-googledrive/src/main/java/com/sshtools/vfs/googledrive/GDriveFileObject.java +++ b/vfs-googledrive/src/main/java/com/sshtools/vfs/googledrive/GDriveFileObject.java @@ -211,6 +211,12 @@ private long processTime(DateTime dateTime) { @Override protected void onChange() throws IOException { this.refresh(); + try { + // TODO: not sure why this sleep is needed but without it creating a file by writing to it and + // then immediately trying to read it fails + Thread.sleep(1000); + } catch (InterruptedException exception) { + } } @Override