From 3a3ddb51ef4c224220303482544761f7a0aa0544 Mon Sep 17 00:00:00 2001 From: uelei Date: Tue, 15 Nov 2022 14:02:37 -0300 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20fix(value):=20Fix=20bug=20pa?= =?UTF-8?q?ssing=20lock=20value=20sync.Mutex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: uelei --- main.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index fd5485b..fac85c1 100644 --- a/main.go +++ b/main.go @@ -35,7 +35,7 @@ func get_local_path(base_dir string) string { return path } -func download_file(c gowebdav.Client, base_dir string, file_name string, server_time time.Time) { +func download_file(c *gowebdav.Client, base_dir string, file_name string, server_time time.Time) { reader, _ := c.ReadStream(base_dir + file_name) full_path := filepath.Join(get_local_path(base_dir), file_name) @@ -51,7 +51,7 @@ func download_file(c gowebdav.Client, base_dir string, file_name string, server_ } } -func upload_file(c gowebdav.Client, base_dir string, file_name string) { +func upload_file(c *gowebdav.Client, base_dir string, file_name string) { full_path := filepath.Join(get_local_path(base_dir), file_name) fmt.Println("Uploading new File ", full_path) @@ -66,7 +66,7 @@ func upload_file(c gowebdav.Client, base_dir string, file_name string) { } -func upload_a_local_folder(c gowebdav.Client, base_dir string, local_folder_name string, local_base_path string) { +func upload_a_local_folder(c *gowebdav.Client, base_dir string, local_folder_name string, local_base_path string) { fmt.Println("uploading local folder ", base_dir, local_folder_name) err := c.Mkdir(base_dir+local_folder_name, 0644) @@ -91,7 +91,7 @@ func upload_a_local_folder(c gowebdav.Client, base_dir string, local_folder_name } } -func check_folder(c gowebdav.Client, base_dir string) { +func check_folder(c *gowebdav.Client, base_dir string) { println("checking base dir = ", base_dir) sync := make(map[string]time.Time) @@ -171,5 +171,5 @@ func main() { } c := gowebdav.NewClient(server, user, password) - check_folder(*c, "/notes/") + check_folder(c, "/notes/") } From 5731f14b9bf16120a341522330ae5acb3593ce9c Mon Sep 17 00:00:00 2001 From: uelei Date: Tue, 15 Nov 2022 15:23:01 -0300 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=94=A7=20refactor(lint):=20Remove=20d?= =?UTF-8?q?eprecated=20call=20to=20io/utils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: uelei --- main.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/main.go b/main.go index fac85c1..99a4e9a 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,6 @@ package main import ( "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -55,7 +54,7 @@ func upload_file(c *gowebdav.Client, base_dir string, file_name string) { full_path := filepath.Join(get_local_path(base_dir), file_name) fmt.Println("Uploading new File ", full_path) - bytes, _ := ioutil.ReadFile(full_path) + bytes, _ := os.ReadFile(full_path) c.Write(filepath.Join(base_dir, file_name), bytes, 0644) @@ -65,7 +64,6 @@ func upload_file(c *gowebdav.Client, base_dir string, file_name string) { c.WriteStream(filepath.Join(base_dir, file_name), fil, 0644) } - func upload_a_local_folder(c *gowebdav.Client, base_dir string, local_folder_name string, local_base_path string) { fmt.Println("uploading local folder ", base_dir, local_folder_name) From 877f27e9766cc4cd80ff27392fd83c3a2307d29e Mon Sep 17 00:00:00 2001 From: uelei Date: Tue, 15 Nov 2022 15:42:18 -0300 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=98=8E=20style(lint):=20fix=20variabl?= =?UTF-8?q?e=20check=20for=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: uelei --- main.go | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 99a4e9a..365de76 100644 --- a/main.go +++ b/main.go @@ -42,7 +42,11 @@ func download_file(c *gowebdav.Client, base_dir string, file_name string, server f, _ := os.Create(full_path) defer f.Close() - io.Copy(f, reader) + _, er := io.Copy(f, reader) + + if er != nil { + fmt.Println(er) + } err := os.Chtimes(full_path, server_time, server_time) if err != nil { @@ -56,12 +60,21 @@ func upload_file(c *gowebdav.Client, base_dir string, file_name string) { fmt.Println("Uploading new File ", full_path) bytes, _ := os.ReadFile(full_path) - c.Write(filepath.Join(base_dir, file_name), bytes, 0644) + er := c.Write(filepath.Join(base_dir, file_name), bytes, 0644) + + if er != nil { + fmt.Println(er) + } fil, _ := os.Open(full_path) defer fil.Close() - c.WriteStream(filepath.Join(base_dir, file_name), fil, 0644) + err := c.WriteStream(filepath.Join(base_dir, file_name), fil, 0644) + + if err != nil { + fmt.Println(err) + } + } func upload_a_local_folder(c *gowebdav.Client, base_dir string, local_folder_name string, local_base_path string) { @@ -106,7 +119,7 @@ func check_folder(c *gowebdav.Client, base_dir string) { check_folder(c, base_dir+file.Name()+"/") } else { full_path := filepath.Join(path, file.Name()) - if doesFileExist(full_path) != true { + if !doesFileExist(full_path) { download_file(c, base_dir, file.Name(), file.ModTime()) } sync[base_dir+file.Name()] = file.ModTime() @@ -120,8 +133,15 @@ func check_folder(c *gowebdav.Client, base_dir string) { fils, err := os.ReadDir(path) if err != nil { fmt.Println("Creating a folder", path) - os.Mkdir(path, os.ModePerm) - for _, file := range files { + + er := os.Mkdir(path, os.ModePerm) + + if er != nil { + fmt.Println(er) + + } + + for _, file := range files { download_file(c, base_dir, file.Name(), file.ModTime()) } }