Skip to content
This repository has been archived by the owner on Jul 27, 2024. It is now read-only.

Update VGriveClient.vala #72

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 34 additions & 19 deletions src/VGriveClient.vala
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace App {
public string trash_path;
public bool syncing = false;
public bool change_detected = false;
public int changes_check_period = 10;
public int changes_check_period = 1;
private Gee.HashMap<string,string>? library;

Thread<int> thread;
Expand Down Expand Up @@ -191,21 +191,22 @@ namespace App {
// Check if we have changes in files and sync them
if (this.is_syncing ()) {
this.log_level=0;
this.check_deleted_files ();
this.check_remote_files (this.main_path);
this.check_local_files (this.main_path);
this.check_deleted_files ();
bcedu marked this conversation as resolved.
Show resolved Hide resolved
this.log_level=1;
if (this.is_syncing ()) {
bcedu marked this conversation as resolved.
Show resolved Hide resolved
this.log_message (_("Everything is up to date!"));
// trigger per revisar canvis quan canvia algo local
this.watch_local_changes ();
// trigger per revisar canvis quan canvia algo remot
this.watch_remote_changes ();
while (this.is_syncing ()) {
Thread.usleep (this.changes_check_period*1000000);
this.process_changes ();
}

this.log_message (_("Everything is up to date!"));
// trigger per revisar canvis quan canvia algo local
this.watch_local_changes ();
// trigger per revisar canvis quan canvia algo remot
this.watch_remote_changes ();

while (this.is_syncing ()) {
Thread.usleep (this.changes_check_period*1000000);
this.process_changes ();
}

return 1;
}else {
return -1;
Expand All @@ -216,7 +217,6 @@ namespace App {
if (this.is_syncing ()) {
if (this.change_detected) {
this.log_message(_("Change detected. Updating files..."));
this.change_detected = false;
this.check_deleted_files ();
this.check_remote_files (this.main_path);
this.check_local_files (this.main_path);
Expand All @@ -228,26 +228,41 @@ namespace App {
return false;
}
}
private void check_deleted_files () {

private void check_deleted_files () {
bcedu marked this conversation as resolved.
Show resolved Hide resolved
// Mira els fitxers que hi ha a la llibreria
// Si no existeixen en local o en remot, el treu de la llibreria i l'elimina de on encara hi sigui
if (!this.is_syncing ()) return;

var it = this.library.map_iterator ();
bool exist_local, exist_remote, must_delete = false;
DriveFile remote_file;
DriveFile[] remote_files;
string remote_id, filename, aux, lpath;
Array<string> to_delete = new Array<string> ();

for (var has_next = it.next (); has_next; has_next = it.next ()) {
if (!this.is_syncing ()) return;
RudahXimenes marked this conversation as resolved.
Show resolved Hide resolved
// Check local exists
lpath = it.get_value();
aux = it.get_key();
filename = lpath.split("/")[lpath.split("/").length-1];
exist_local = this.local_file_exists(lpath);

// Check remote exists
remote_id = this.get_file_id(lpath);
exist_remote = remote_id != null && remote_id != "";
/*
EXPERIMENTAL REMOTE CHECKING
Note: could be incremented checking if the remote file is trased or not. If trashed, exist_remote should be false, otherwise should be true
*/
remote_files = this.list_files(-1, lpath, -1);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method list_files returns all the files childs of lpath. Why do you use the list method?
It's more efficient to ask only for the file we are checking with get_file_id instead of listing all the files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put this to try understand better why this delete function is deleting files that exists in both remote and local.

I have 3 guesses:

  1. Could be the remote checking that don't retrieve the files properly; or
  2. Could be the local checking that is retrieving the filenames wrong; or
  3. The escape function that is somehow messing up with the file names.

My thought was try to change the remote checking to make sure it's not it.

I know that is not efficient and I don't want to leave like that, but I want to make sure that the bug keep occurring, so we can put the remote check aside and turn back into get_file_id

Makes sense what I'm trying to do?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it make sense.

Where I have got more problems is in the escape function with filenames that have "special" characters. Could you give me some "problematic" filename that you have detected?

Copy link
Contributor Author

@RudahXimenes RudahXimenes Jan 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some special caracters were something like:
~
#
accents in general (á ã õ ó)

But I don't think we need to escape this anymore. I made a lot of changes in the checking functions and seems to work fine with caracters.


foreach(DriveFile f in remote_files){
if(f.name == filename){
exist_remote = true;
}
}
//END OF EXPERIMENTAL

//remote_id = this.get_file_id(lpath);
//exist_remote = remote_id != null && remote_id != "";

// Si fa falta, l'eliminem de on sigui (fa falta si en un dels dos llocs s'ha de eliminar
must_delete = !exist_local || !exist_remote;
Expand Down Expand Up @@ -380,7 +395,7 @@ namespace App {
try {
new Thread<int>.try ("Watch remote thread", () => {
while (this.is_syncing ()) {
Thread.usleep (this.changes_check_period*1000000);
//Thread.usleep (this.changes_check_period*1000000);
bcedu marked this conversation as resolved.
Show resolved Hide resolved
this.change_detected = this.check_remote_changes (this.page_token);
}
new MainLoop ().run ();
Expand Down