python-fsutil
python-fsutil copied to clipboard
Bug report related to _write_file_atomic() in Windows environment
Dear python-fsutil developers
I encountered a file write error on Windows environment while using the django-maintenance-mode package. First, I reported it on the django-maintenance-mode issue tracker(#180), and since it's actually an fsutil issue, fabiocaccamo asked me to report it here, so I'll report it here.
Environment
- OS: Windows 11 Home 23H2
- pyenv-win 3.1.1
- Python 3.10.11
- Django 3.2
- Django maintenance mode 0.21.1
- Python-fsutil 0.13.1
Current behavior (bug description) I confirmed 2 defects.
(1) _write_file_atomic() fails to create files: When fsutil.write_file() function was called, _write_file_atomic() was called to create maintenance_mode_state.txt, but maintenance_mode_state.txt was not created. No exception is raised in _write_file_atomic(), but afterward assert_file() is called in fsutil.read_file() afterwards and raises an OSError exception. Actually, FileNotFoundError: [WinError 2] occurs in the isfile() function in the builtin genericpath.py, which is called by assert_file().
(2) _write_file_atomic() deletes existing files:
Due to the above issue, I manually created the maintenance_mode_state.txt file in advance and then ran the command below.
$ python manage.py maintenance_mode on
This command uses _write_file_atomic() to write characters to the maintenance_mode_state.txt file, but I confirmed that the maintenance_mode_state.txt file disappeared during this function.
No Problem In Linux Environment I have confirmed that there is no problem described above in Linux environment.
That's all I've come across. Thank you for your time and assistance.
Upvote & Fund
- We're using Polar.sh so you can upvote and help fund this issue.
- We receive the funding once the issue is completed & confirmed by you.
- Thank you in advance for helping prioritize & fund our backlog.
@SatoTake2019 thank you for having moved the issue, this repository is mine too :)
Thank you for the detailed debug!
- do you think you can write a failing test that proves the bug on Windows?
- can you check the directory file permissions please?
Please allow a day or so for me to answer your question.
@fabiocaccamo I'm sorry, but I do not have spare time to make test. Because I am fully committed to the development of my ongoing projects. In the future, when my project is finished and the situation changes, I think I may be able to cooperate with you. The permissions of files created with GitBash in my Windows environment are as follows.
$ ls -laF myapps/config/settings/maintenance_mode_state.txt
-rw-r--r-- 1 toque 197121 0 Feb 13 19:59 myapps/config/settings/maintenance_mode_state.txt
$ whoami
toque
$ echo $SHELL
/usr/bin/bash
$ bash --version
GNU bash, version 5.2.21(1)-release (x86_64-pc-msys)
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
@SatoTake2019 ok, since I can't reproduce it, I close the issue for now, when you will be able to provide more informations I will be glad to reopen it.