mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-12 01:18: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=""):
|
def get_text_from_editor(config, template=""):
|
||||||
filehandle, tmpfile = tempfile.mkstemp(prefix="jrnl", text=True, suffix=".txt")
|
filehandle, tmpfile = tempfile.mkstemp(prefix="jrnl", text=True, suffix=".txt")
|
||||||
|
os.close(filehandle)
|
||||||
|
|
||||||
with open(tmpfile, "w", encoding="utf-8") as f:
|
with open(tmpfile, "w", encoding="utf-8") as f:
|
||||||
if template:
|
if template:
|
||||||
f.write(template)
|
f.write(template)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.call(
|
subprocess.call(
|
||||||
shlex.split(config["editor"], posix="win" not in sys.platform) + [tmpfile]
|
shlex.split(config["editor"], posix="win" not in sys.platform) + [tmpfile]
|
||||||
)
|
)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
subprocess.call(config["editor"] + [tmpfile])
|
subprocess.call(config["editor"] + [tmpfile])
|
||||||
|
|
||||||
with open(tmpfile, "r", encoding="utf-8") as f:
|
with open(tmpfile, "r", encoding="utf-8") as f:
|
||||||
raw = f.read()
|
raw = f.read()
|
||||||
os.close(filehandle)
|
|
||||||
os.remove(tmpfile)
|
os.remove(tmpfile)
|
||||||
|
|
||||||
if not raw:
|
if not raw:
|
||||||
print("[Nothing saved to file]", file=sys.stderr)
|
print("[Nothing saved to file]", file=sys.stderr)
|
||||||
|
|
||||||
return raw
|
return raw
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue