Handle FileNotFoundError coming from os.path.samefile

This commit is contained in:
Isaiah Odhner 2023-04-20 12:08:03 -04:00
parent 61d1532552
commit ec4d044f8a

View File

@ -1229,10 +1229,11 @@ class PaintApp(App):
if self.directory_tree_selected_path: if self.directory_tree_selected_path:
filename = os.path.join(self.directory_tree_selected_path, filename) filename = os.path.join(self.directory_tree_selected_path, filename)
if filename: if filename:
if self.filename and os.path.samefile(filename, self.filename):
window.close()
return
try: try:
# Note that os.path.samefile can raise FileNotFoundError
if self.filename and os.path.samefile(filename, self.filename):
window.close()
return
with open(filename, "r") as f: with open(filename, "r") as f:
content = f.read() # f is out of scope in go_ahead() content = f.read() # f is out of scope in go_ahead()
def go_ahead(): def go_ahead():