Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close temp file before passing it to editor to prevent file locking issues in Windows #792

Merged
merged 1 commit into from Jan 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion jrnl/util.py
Expand Up @@ -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


Expand Down