From 0c2bd15cd1802e098b107c724c675421d3b1c6e4 Mon Sep 17 00:00:00 2001 From: Rodrigo Leite Date: Fri, 3 Jan 2020 01:46:46 -0300 Subject: [PATCH 1/6] proton: Check if directory exists before attempting to create --- proton | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/proton b/proton index 22b5112986..251703d257 100755 --- a/proton +++ b/proton @@ -45,9 +45,11 @@ def file_is_wine_fake_dll(path): def makedirs(path): try: + if os.path.lexists(path): + return + os.makedirs(path) except OSError: - #already exists pass def try_copy(src, dst): From 02d0377110de0555754e34e7c46b3fa8c559fb71 Mon Sep 17 00:00:00 2001 From: Rodrigo Leite Date: Fri, 3 Jan 2020 01:47:44 -0300 Subject: [PATCH 2/6] proton: Add error logging in makedirs --- proton | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/proton b/proton index 251703d257..ff1d2ecdb5 100755 --- a/proton +++ b/proton @@ -49,7 +49,8 @@ def makedirs(path): return os.makedirs(path) - except OSError: + except OSError as err: + log("Error when creating directory {0}: {1}".format(path, err)) pass def try_copy(src, dst): From eb08e1f64f4ae690855ce35544976817b5f581fe Mon Sep 17 00:00:00 2001 From: Rodrigo Leite Date: Fri, 3 Jan 2020 01:48:19 -0300 Subject: [PATCH 3/6] proton: Standardize use of makedirs --- proton | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proton b/proton index ff1d2ecdb5..1dcc7927fd 100755 --- a/proton +++ b/proton @@ -260,7 +260,7 @@ class CompatData: rel_dir = rel_dir + "/" dst_dir = src_dir.replace(g_proton.default_pfx_dir, self.prefix_dir, 1) if not os.path.exists(dst_dir): - os.makedirs(dst_dir) + makedirs(dst_dir) tracked_files.write(rel_dir + "\n") for dir_ in dirs: src_file = os.path.join(src_dir, dir_) From 09be8efd5d1f9b85f533e7a81ba55c8d7553f5ae Mon Sep 17 00:00:00 2001 From: Rodrigo Leite Date: Sat, 4 Jan 2020 20:18:24 -0300 Subject: [PATCH 4/6] proton: Check if directory is empty before removing and log OSError --- proton | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/proton b/proton index 1dcc7927fd..262aa53eae 100755 --- a/proton +++ b/proton @@ -168,9 +168,10 @@ class CompatData: dirs.append(path) for d in dirs: try: - os.rmdir(d) - except OSError: - #not empty + if len(os.listdir(d)) != 0: + os.rmdir(d) + except OSError as err: + log("Error deleting directory {0}: {1}".format(d, err)) pass os.remove(self.tracked_files_file) From da569c1602c6c28f07646ce3f2e2b84de6c13e6c Mon Sep 17 00:00:00 2001 From: Rodrigo Leite Date: Mon, 6 Jan 2020 15:00:12 -0300 Subject: [PATCH 5/6] proton: Use scandir to check if directory is empty --- proton | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proton b/proton index 262aa53eae..c730884e70 100755 --- a/proton +++ b/proton @@ -168,7 +168,7 @@ class CompatData: dirs.append(path) for d in dirs: try: - if len(os.listdir(d)) != 0: + if not any(os.scandir(d)): os.rmdir(d) except OSError as err: log("Error deleting directory {0}: {1}".format(d, err)) From 644a257ab696321faa8fd1b57e7d1c51f242a16c Mon Sep 17 00:00:00 2001 From: Rodrigo Leite Date: Tue, 4 Feb 2020 18:28:27 -0300 Subject: [PATCH 6/6] Raise error instead of manually logging --- proton | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/proton b/proton index c730884e70..9550b810bf 100755 --- a/proton +++ b/proton @@ -49,8 +49,7 @@ def makedirs(path): return os.makedirs(path) - except OSError as err: - log("Error when creating directory {0}: {1}".format(path, err)) + except FileExistsError: pass def try_copy(src, dst): @@ -170,9 +169,9 @@ class CompatData: try: if not any(os.scandir(d)): os.rmdir(d) - except OSError as err: - log("Error deleting directory {0}: {1}".format(d, err)) - pass + except OSError as e: + if e.errno != errno.ENOTEMPTY: + raise os.remove(self.tracked_files_file) os.remove(self.version_file)