proton: Double-check to avoid locking, if unnecessary

This commit is contained in:
Alan 2020-05-12 11:12:38 +02:00 committed by Andrew Eikum
parent c6a40b9947
commit 6e821c774f

18
proton
View File

@ -107,11 +107,15 @@ class Proton:
def path(self, d): def path(self, d):
return self.base_dir + d return self.base_dir + d
def need_tarball_extraction(self):
'''Checks if the proton_dist tarball archive must be extracted. Returns true if extraction is needed, false otherwise'''
return not os.path.exists(self.dist_dir) or \
not os.path.exists(self.path("dist/version")) or \
not filecmp.cmp(self.version_file, self.path("dist/version"))
def extract_tarball(self): def extract_tarball(self):
with self.dist_lock: with self.dist_lock:
if not os.path.exists(self.dist_dir) or \ if self.need_tarball_extraction():
not os.path.exists(self.path("dist/version")) or \
not filecmp.cmp(self.version_file, self.path("dist/version")):
if os.path.exists(self.dist_dir): if os.path.exists(self.dist_dir):
shutil.rmtree(self.dist_dir) shutil.rmtree(self.dist_dir)
tar = None tar = None
@ -126,10 +130,14 @@ class Proton:
tar.close() tar.close()
try_copy(self.version_file, self.dist_dir) try_copy(self.version_file, self.dist_dir)
def missing_default_prefix(self):
'''Check if the default prefix dir is missing. Returns true if missing, false if present'''
return not os.path.isdir(self.default_pfx_dir)
def make_default_prefix(self): def make_default_prefix(self):
with self.dist_lock: with self.dist_lock:
local_env = dict(g_session.env) local_env = dict(g_session.env)
if not os.path.isdir(self.default_pfx_dir): if self.missing_default_prefix():
#make default prefix #make default prefix
local_env["WINEPREFIX"] = self.default_pfx_dir local_env["WINEPREFIX"] = self.default_pfx_dir
local_env["WINEDEBUG"] = "-all" local_env["WINEDEBUG"] = "-all"
@ -670,6 +678,7 @@ if __name__ == "__main__":
g_proton = Proton(os.path.dirname(sys.argv[0])) g_proton = Proton(os.path.dirname(sys.argv[0]))
if g_proton.need_tarball_extraction():
g_proton.extract_tarball() g_proton.extract_tarball()
g_compatdata = CompatData(os.environ["STEAM_COMPAT_DATA_PATH"]) g_compatdata = CompatData(os.environ["STEAM_COMPAT_DATA_PATH"])
@ -678,6 +687,7 @@ if __name__ == "__main__":
g_session.init_wine() g_session.init_wine()
if g_proton.missing_default_prefix():
g_proton.make_default_prefix() g_proton.make_default_prefix()
g_session.init_session() g_session.init_session()