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

22
proton
View file

@ -107,11 +107,15 @@ class Proton:
def path(self, 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):
with self.dist_lock:
if 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")):
if self.need_tarball_extraction():
if os.path.exists(self.dist_dir):
shutil.rmtree(self.dist_dir)
tar = None
@ -126,10 +130,14 @@ class Proton:
tar.close()
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):
with self.dist_lock:
local_env = dict(g_session.env)
if not os.path.isdir(self.default_pfx_dir):
if self.missing_default_prefix():
#make default prefix
local_env["WINEPREFIX"] = self.default_pfx_dir
local_env["WINEDEBUG"] = "-all"
@ -670,7 +678,8 @@ if __name__ == "__main__":
g_proton = Proton(os.path.dirname(sys.argv[0]))
g_proton.extract_tarball()
if g_proton.need_tarball_extraction():
g_proton.extract_tarball()
g_compatdata = CompatData(os.environ["STEAM_COMPAT_DATA_PATH"])
@ -678,7 +687,8 @@ if __name__ == "__main__":
g_session.init_wine()
g_proton.make_default_prefix()
if g_proton.missing_default_prefix():
g_proton.make_default_prefix()
g_session.init_session()