Skip to content

Commit

Permalink
Reduce mount time + add "Shared with me" directory
Browse files Browse the repository at this point in the history
  • Loading branch information
harababurel committed Aug 1, 2018
1 parent a3942b0 commit ad5d8bb
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "gcsf"
description = "Filesystem based on Google Drive"
version = "0.1.16"
version = "0.1.17"
repository = "https://github.com/harababurel/gcsf"
authors = ["Sergiu Puscas <srg.pscs@gmail.com>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/cli.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: GCSF
version: "0.1.16"
version: "0.1.17"
author: Sergiu Puscas <srg.pscs@gmail.com>
about: File system based on Google Drive
subcommands:
Expand Down
11 changes: 10 additions & 1 deletion src/gcsf/drive_facade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ impl DriveFacade {
) -> Result<Vec<drive3::File>, Error> {
let mut all_files = Vec::new();
let mut page_token: Option<String> = None;
let mut current_page = 1;
loop {
let mut request = self.hub.files()
.list()
Expand Down Expand Up @@ -353,10 +354,18 @@ impl DriveFacade {
.map_err(|e| err_msg(format!("{:#?}", e)))?;

match filelist.files {
Some(files) => all_files.extend(files),
Some(files) => {
info!(
"Received page {} containing {} files",
current_page,
files.len()
);
all_files.extend(files);
}
_ => warn!("Filelist does not contain any files!"),
};

current_page += 1;
page_token = filelist.next_page_token;
if page_token.is_none() {
break;
Expand Down
44 changes: 18 additions & 26 deletions src/gcsf/file_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub type DriveId = String;

const ROOT_INODE: Inode = 1;
const TRASH_INODE: Inode = 2;
const SHARED_INODE: Inode = 3;

macro_rules! unwrap_or_continue {
($res:expr) => {
Expand Down Expand Up @@ -152,40 +153,31 @@ impl FileManager {
Ok(())
}

/// Retrieves all files and directories shown in "My Drive" and adds them locally.
/// Retrieves all files and directories shown in "My Drive" and "Shared with me" and adds them locally.
fn populate(&mut self) -> Result<(), Error> {
let root = self.new_root_file()?;
self.add_file_locally(root, None)?;

let mut queue: LinkedList<DriveId> = LinkedList::new();
queue.push_back(self.df.root_id().unwrap_or(&"root".to_string()).to_string());
let shared = self.new_special_dir("Shared with me", Some(SHARED_INODE));
self.add_file_locally(shared, Some(FileId::Inode(ROOT_INODE)))?;

while !queue.is_empty() {
let mut parents = Vec::new();
while !queue.is_empty() {
parents.push(queue.pop_front().unwrap());
}

for drive_file in self.df.get_all_files(Some(parents), Some(false))? {
let mut file = File::from_drive_file(self.next_available_inode(), drive_file);
for drive_file in self.df.get_all_files(None, Some(false))? {
let mut file = File::from_drive_file(self.next_available_inode(), drive_file);
self.add_file_locally(file, Some(FileId::Inode(3)))?;
}

if file.kind() == FileType::Directory {
queue.push_back(file.drive_id().unwrap());
let mut moves: LinkedList<(FileId, FileId)> = LinkedList::new();
for (inode, file) in &self.files {
if let Some(parent) = file.drive_parent() {
if self.contains(&FileId::DriveId(parent.clone())) {
moves.push_back((FileId::Inode(*inode), FileId::DriveId(parent)));
}
}
}

// TODO: this makes everything slow; find a better solution
// if file.is_drive_document() {
// let size = drive_facade
// .get_file_size(file.drive_id().as_ref().unwrap(), file.mime_type());
// file.attr.size = size;
// }

let file_parent = file.drive_parent().unwrap();
if self.contains(&FileId::DriveId(file_parent.clone())) {
self.add_file_locally(file, Some(FileId::DriveId(file_parent.clone())))?;
} else {
self.add_file_locally(file, None)?;
}
for (inode, parent) in &moves {
if let Err(e) = self.move_locally(inode, parent) {
error!("{}", e);
}
}

Expand Down

0 comments on commit ad5d8bb

Please sign in to comment.