diff --git a/data/com.github.bcedu.vgrive.appdata.xml.in b/data/com.github.bcedu.vgrive.appdata.xml.in index 312d7bb..fad5ba9 100644 --- a/data/com.github.bcedu.vgrive.appdata.xml.in +++ b/data/com.github.bcedu.vgrive.appdata.xml.in @@ -37,6 +37,12 @@ Automatically detects changes in local and remote files and syncs them.

+ + +

Adapt to changes of Google Drive API

+

Avoid error "may be sending authomated queries"

+
+

Bug fixed that caused deleting some files that had special characters.

diff --git a/debian/changelog b/debian/changelog index a215185..d944f70 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -com.github.bcedu.vgrive (1.5.0) precise; urgency=low +com.github.bcedu.vgrive (1.6.0) precise; urgency=low [ Eduard Berloso Clarà ] * Juno release of VGrive. diff --git a/src/VGriveClient.vala b/src/VGriveClient.vala index 03e4a78..e3466c9 100644 --- a/src/VGriveClient.vala +++ b/src/VGriveClient.vala @@ -593,10 +593,18 @@ namespace App { public ResponseObject make_request(string method, string uri, RequestParam[]? params_list=null, RequestParam[]? request_headers=null, RequestContent? request_content=null, bool without_acces_token=false) throws ErrorGoogleDriveAPI { // Fa una petició HTTP a la API de Google Drive amb els paràmetres proporcionats var session = this.get_current_session(); - string uri_auth; - if (without_acces_token) uri_auth = uri; - else uri_auth = uri + "?access_token=%s".printf(this.access_token); - if (params_list != null) foreach (RequestParam param in params_list) uri_auth = uri_auth.concat("&", param.field_name, "=", param.field_value); + string uri_auth = uri; + bool is_first; + if (params_list != null) { + is_first = true; + foreach (RequestParam param in params_list) { + if (is_first) { + is_first = false; + uri_auth = uri_auth.concat("?", param.field_name, "=", param.field_value); + } + else uri_auth = uri_auth.concat("&", param.field_name, "=", param.field_value); + } + } uri_auth = encode_uri(uri_auth); var message = new Soup.Message (method, uri_auth); string res; @@ -604,8 +612,10 @@ namespace App { Soup.MessageHeaders res_header = null; try { // send the HTTP request and wait for response + if (!without_acces_token) message.request_headers.append("Authorization", "Bearer %s".printf(this.access_token)); if (request_headers != null) foreach (RequestParam param in request_headers) message.request_headers.append(param.field_name, param.field_value); if (request_content != null) message.set_request(request_content.content_type, Soup.MemoryUse.COPY, request_content.content); + session.send_message (message); bres = message.response_body.data; res = (string) message.response_body.data; @@ -636,14 +646,13 @@ namespace App { if (json_response.get_member("access_token") != null) { // Retry request with new token this.access_token = json_response.get_string_member("access_token"); - if (without_acces_token) uri_auth = uri; - else uri_auth = uri + "?access_token=%s".printf(this.access_token); - if (params_list != null) foreach (RequestParam param in params_list) uri_auth = uri_auth.concat("&", param.field_name, "=", param.field_value); uri_auth = encode_uri(uri_auth); //stdout.printf("Retrying request: %s %s\n", method, uri_auth); message = new Soup.Message (method, uri_auth); + if (!without_acces_token) message.request_headers.append("Authorization", "Bearer %s".printf(this.access_token)); if (request_headers != null) foreach (RequestParam param in request_headers) message.request_headers.append(param.field_name, param.field_value); if (request_content != null) message.set_request(request_content.content_type, Soup.MemoryUse.COPY, request_content.content); + session.send_message (message); bres = message.response_body.data; res = (string) message.response_body.data; diff --git a/tests/vgrive_tests.vala b/tests/vgrive_tests.vala index a5d3630..b48ab50 100644 --- a/tests/vgrive_tests.vala +++ b/tests/vgrive_tests.vala @@ -6,8 +6,8 @@ class TestVGrive : Gee.TestCase { private VGriveClient client; private string mainpath = GLib.Environment.get_current_dir()+"/.testbuild/VGriveTEST"; - private string access_token = "ya29.Il_BB3zFXkNQ22kLVBhaPUQlSNBK0PEH2B6BYW9v1kW_PzfD7r9wDw_QGDgsEXeCxwo2keeXWFgQQk-04NN9yvUstc4K-Lr0QwEGpdR4BsB5J0KHkGQGAXQAF14ToPjTOw"; - private string refresh_token = "1//03IU2IIEPTdKeCgYIARAAGAMSNwF-L9IrnsAzIRFCLUjFKG7JQGknE2jswVrNfSMkI4GX53J8GS0eJcVrfC68zRFGKIrmWb9_OLk"; + private string access_token = "ya29.a0Ae4lvC01aowtxNp3MPnc2eAF_eSsyc3FSgZJ_BaleYqvu23I_P4--4WOBbe6csNj1KcXwTHh1jF8UNRmi_shFJ4tsUH3CgKLl-YRu2Ab69MVq2IIQ5Wh1mEAA5AZEBPAtB_hq4UE5G_GE-V58jBd03z9R167JRMNiag"; + private string refresh_token = "1//03TTG3NNWnzjtCgYIARAAGAMSNwF-L9Iri6xRlra2E7wk740u2eUeaksEEnpwFQQLX_F5BIZRxLveowOqCefPfVyKk062JkZb4qw"; public TestVGrive() { // assign a name for this class @@ -31,9 +31,9 @@ class TestVGrive : Gee.TestCase { add_test(" * Test if some files are google documents or not (test_is_google_doc_and_is_google_mime_type)", test_is_google_doc_and_is_google_mime_type); add_test(" * Test get google drive information of file (test_get_file_info)", test_get_file_info); add_test(" * Test get google drive extra information of file (test_get_file_info_extra)", test_get_file_info_extra); - add_test(" * Test check if there are pending changes in google drive (test_has_remote_changes_and_request_page_token)", test_has_remote_changes_and_request_page_token); add_test(" * Test starting a new sync process and stop it (test_start_and_stop_syncing)", test_start_and_stop_syncing); add_test(" * Test starting the sync process to check deleted files (test_check_deleted_files)", test_check_deleted_files); + add_test(" * Test check if there are pending changes in google drive (test_has_remote_changes_and_request_page_token)", test_has_remote_changes_and_request_page_token); } public override void set_up () { @@ -292,19 +292,15 @@ class TestVGrive : Gee.TestCase { * * */ // Fitxer a una subcarpeta - try { - string file_id = this.client.get_file_id (this.mainpath+"/Muse/Millors/muse.txt"); - assert (file_id != ""); - uint8[] content = this.client.get_file_content (file_id); - assert_strings (content, get_fixture_content ("muse.txt", false)); - // Fitxer a root - file_id = this.client.get_file_id (this.mainpath+"/muse.txt"); - assert (file_id != ""); - content = this.client.get_file_content (file_id); - assert_strings (content, get_fixture_content ("muse.txt", false)); - } catch (ErrorGoogleDriveAPI e) { - assert_strings (e.message.data, "Google Drive Connection Error: google drive has blocked your IP, VGrive can't sync files while google drive continue blocking the IP...".data); - } + string file_id = this.client.get_file_id (this.mainpath+"/Muse/Millors/muse.txt"); + assert (file_id != ""); + uint8[] content = this.client.get_file_content (file_id); + assert_strings (content, get_fixture_content ("muse.txt", false)); + // Fitxer a root + file_id = this.client.get_file_id (this.mainpath+"/muse.txt"); + assert (file_id != ""); + content = this.client.get_file_content (file_id); + assert_strings (content, get_fixture_content ("muse.txt", false)); } public void test_get_file_id_of_main_path () { @@ -375,25 +371,21 @@ class TestVGrive : Gee.TestCase { * * */ // Pujem el fitxer a root - try { - var res = this.client.upload_file (GLib.Environment.get_current_dir()+"/tests/fixtures/muse_new_to_upload.txt", "root"); - assert (res.name == "muse_new_to_upload.txt"); - assert (res.id != null); - assert (res.trashed == false); - assert (res.parent_id == "root"); - // Obtenim el contingut per asegurarnos que la versio es l'antiga - uint8[] content = this.client.get_file_content (res.id); - assert_strings (content, get_fixture_content ("muse_new_to_upload.txt", false)); - // Pujem la nova versio - this.client.upload_file_update (GLib.Environment.get_current_dir()+"/tests/fixtures/muse_new_to_upload.v2.txt", res.id); - // Obtenim el contingut per asegurarnos que la versio es la nova - content = this.client.get_file_content (res.id); - assert_strings (content, get_fixture_content ("muse_new_to_upload.v2.txt", false)); - // Eliminem el fitxer - this.client.delete_file (res.id); - } catch (ErrorGoogleDriveAPI e) { - assert_strings (e.message.data, "Google Drive Connection Error: google drive has blocked your IP, VGrive can't sync files while google drive continue blocking the IP...".data); - } + var res = this.client.upload_file (GLib.Environment.get_current_dir()+"/tests/fixtures/muse_new_to_upload.txt", "root"); + assert (res.name == "muse_new_to_upload.txt"); + assert (res.id != null); + assert (res.trashed == false); + assert (res.parent_id == "root"); + // Obtenim el contingut per asegurarnos que la versio es l'antiga + uint8[] content = this.client.get_file_content (res.id); + assert_strings (content, get_fixture_content ("muse_new_to_upload.txt", false)); + // Pujem la nova versio + this.client.upload_file_update (GLib.Environment.get_current_dir()+"/tests/fixtures/muse_new_to_upload.v2.txt", res.id); + // Obtenim el contingut per asegurarnos que la versio es la nova + content = this.client.get_file_content (res.id); + assert_strings (content, get_fixture_content ("muse_new_to_upload.v2.txt", false)); + // Eliminem el fitxer + this.client.delete_file (res.id); } public void test_upload_dir_main_path () { @@ -717,53 +709,49 @@ class TestVGrive : Gee.TestCase { * * */ // Ho preparem tot - try { - DriveFile res = this.add_file_to_drive (GLib.Environment.get_current_dir()+"/tests/fixtures/muse_new_to_upload.txt", "", "root"); - DriveFile res2 = this.add_file_to_drive (GLib.Environment.get_current_dir()+"/tests/fixtures/muse_new_to_upload.v2.txt", "", "root"); - DriveFile res3 = this.add_file_to_drive (GLib.Environment.get_current_dir()+"/tests/fixtures/muse_new_to_upload.v3.txt", "", "root"); - this.client.move_local_file_to_trash(this.mainpath+"/muse_new_to_upload.v3.txt"); - this.client.delete_file(res2.id); - - File f = File.new_for_path(this.mainpath+"/muse_new_to_upload.txt"); - assert(f.query_exists() == true); - DriveFile[] found_files = this.client.search_files ("trashed = False and name = '%s' and 'root' in parents".printf (res.name)); - assert (found_files.length == 1); - - f = File.new_for_path(this.mainpath+"/muse_new_to_upload.v2.txt"); - assert(f.query_exists() == true); - found_files = this.client.search_files ("trashed = False and name = '%s' and 'root' in parents".printf (res2.name)); - assert (found_files.length == 0); - - f = File.new_for_path(this.mainpath+"/muse_new_to_upload.v3.txt"); - assert(f.query_exists() == false); - found_files = this.client.search_files ("trashed = False and name = '%s' and 'root' in parents".printf (res3.name)); - assert (found_files.length == 1); - - // Executem el metode - this.client.syncing = true; - this.client.check_deleted_files (); - - // Comprovem que hagi passat el que esperavem - f = File.new_for_path(this.mainpath+"/muse_new_to_upload.txt"); - assert(f.query_exists() == true); - found_files = this.client.search_files ("trashed = False and name = '%s' and 'root' in parents".printf (res.name)); - assert (found_files.length == 1); - - f = File.new_for_path(this.mainpath+"/muse_new_to_upload.v2.txt"); - assert(f.query_exists() == false); - found_files = this.client.search_files ("trashed = False and name = '%s' and 'root' in parents".printf (res2.name)); - assert (found_files.length == 0); - - f = File.new_for_path(this.mainpath+"/muse_new_to_upload.v3.txt"); - assert(f.query_exists() == false); - found_files = this.client.search_files ("trashed = False and name = '%s' and 'root' in parents".printf (res3.name)); - assert (found_files.length == 0); - - // Netegem fitxers - this.client.delete_file (res.id); - } catch (ErrorGoogleDriveAPI e) { - assert_strings (e.message.data, "Google Drive Connection Error: google drive has blocked your IP, VGrive can't sync files while google drive continue blocking the IP...".data); - } + DriveFile res = this.add_file_to_drive (GLib.Environment.get_current_dir()+"/tests/fixtures/muse_new_to_upload.txt", "", "root"); + DriveFile res2 = this.add_file_to_drive (GLib.Environment.get_current_dir()+"/tests/fixtures/muse_new_to_upload.v2.txt", "", "root"); + DriveFile res3 = this.add_file_to_drive (GLib.Environment.get_current_dir()+"/tests/fixtures/muse_new_to_upload.v3.txt", "", "root"); + this.client.move_local_file_to_trash(this.mainpath+"/muse_new_to_upload.v3.txt"); + this.client.delete_file(res2.id); + + File f = File.new_for_path(this.mainpath+"/muse_new_to_upload.txt"); + assert(f.query_exists() == true); + DriveFile[] found_files = this.client.search_files ("trashed = False and name = '%s' and 'root' in parents".printf (res.name)); + assert (found_files.length == 1); + + f = File.new_for_path(this.mainpath+"/muse_new_to_upload.v2.txt"); + assert(f.query_exists() == true); + found_files = this.client.search_files ("trashed = False and name = '%s' and 'root' in parents".printf (res2.name)); + assert (found_files.length == 0); + + f = File.new_for_path(this.mainpath+"/muse_new_to_upload.v3.txt"); + assert(f.query_exists() == false); + found_files = this.client.search_files ("trashed = False and name = '%s' and 'root' in parents".printf (res3.name)); + assert (found_files.length == 1); + + // Executem el metode + this.client.syncing = true; + this.client.check_deleted_files (); + + // Comprovem que hagi passat el que esperavem + f = File.new_for_path(this.mainpath+"/muse_new_to_upload.txt"); + assert(f.query_exists() == true); + found_files = this.client.search_files ("trashed = False and name = '%s' and 'root' in parents".printf (res.name)); + assert (found_files.length == 1); + + f = File.new_for_path(this.mainpath+"/muse_new_to_upload.v2.txt"); + assert(f.query_exists() == false); + found_files = this.client.search_files ("trashed = False and name = '%s' and 'root' in parents".printf (res2.name)); + assert (found_files.length == 0); + + f = File.new_for_path(this.mainpath+"/muse_new_to_upload.v3.txt"); + assert(f.query_exists() == false); + found_files = this.client.search_files ("trashed = False and name = '%s' and 'root' in parents".printf (res3.name)); + assert (found_files.length == 0); + + // Netegem fitxers + this.client.delete_file (res.id); } }