mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
#790 - closing temp file before passing it to editor to prevent file locking issues in Windows
This commit is contained in:
parent
1b64bb4a86
commit
373033a285
1 changed files with 6 additions and 1 deletions
|
@ -142,21 +142,26 @@ def scope_config(config, journal_name):
|
|||
|
||||
def get_text_from_editor(config, template=""):
|
||||
filehandle, tmpfile = tempfile.mkstemp(prefix="jrnl", text=True, suffix=".txt")
|
||||
os.close(filehandle)
|
||||
|
||||
with open(tmpfile, "w", encoding="utf-8") as f:
|
||||
if template:
|
||||
f.write(template)
|
||||
|
||||
try:
|
||||
subprocess.call(
|
||||
shlex.split(config["editor"], posix="win" not in sys.platform) + [tmpfile]
|
||||
)
|
||||
except AttributeError:
|
||||
subprocess.call(config["editor"] + [tmpfile])
|
||||
|
||||
with open(tmpfile, "r", encoding="utf-8") as f:
|
||||
raw = f.read()
|
||||
os.close(filehandle)
|
||||
os.remove(tmpfile)
|
||||
|
||||
if not raw:
|
||||
print("[Nothing saved to file]", file=sys.stderr)
|
||||
|
||||
return raw
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue