pixelb / crudini

A utility for manipulating ini files
GNU General Public License v2.0
443 stars 63 forks source link

Win: msvcrt lock error #61

Closed 1480c1 closed 2 years ago

1480c1 commented 5 years ago
Traceback (most recent call last):
  File "./crudini", line 979, in <module>
    sys.exit(main())
  File "./crudini", line 975, in main
    return crudini.run()
  File "./crudini", line 869, in run
    preserve_case=preserve_case)
  File "./crudini", line 648, in parse_file
    not self.update)
  File "./crudini", line 165, in __init__
    self.lock()
  File "./crudini", line 96, in lock
    msvcrt.locking(self.fp, msvcrt.LK_LOCK, 1)
TypeError: an integer is required

Windows 10 python installed through choco install python2

choco install python2
python -m pip install --upgrade pip
pip install iniparse
python ./crudini --get example.ini '' global

python ./crudini --help and version work fine

pixelb commented 5 years ago

I'll need to get access to a windows machine to debug this

domgreen commented 3 years ago

I ran into this today:

I changed the code for locking in windows to be like this:

if os.name == 'nt':
            import msvcrt

            def lock(self):
                msvcrt.locking(self.fp.fileno(), msvcrt.LK_LOCK, 1)
                self.locked = True

            def unlock(self):
                if self.locked:
                    msvcrt.locking(self.fp.fileno(), msvcrt.LK_UNLCK, 1)
                self.locked = False

However, with this I still get an error unlocking the file:

Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File ".\crudini\crudini.py", line 193, in delete
    self.unlock()
  File ".\crudini\crudini.py", line 101, in unlock
    msvcrt.locking(self.fp.fileno(), msvcrt.LK_UNLCK, 32)
PermissionError: [Errno 13] Permission denied
domgreen commented 3 years ago

Switching lib to portalocker seems to work ... will put out a PR once ive done some more testing:

import portalocker

def lock(self):
    portalocker.lock(self.fp, portalocker.LOCK_EX)
    self.locked = True

def unlock(self):
    if self.locked:
        portalocker.unlock(self.fp)
    self.locked = False
domgreen commented 3 years ago

Ahhh even though that works not been able to get set to work on Windows:

[WinError 5] Access is denied: 'C:\\Dev\\crudini\\example.ini.3ureg9f8.tmp' -> 'C:\\Dev\\crudini\\example.ini'

This is even running as admin happens on this line https://github.com/pixelb/crudini/blob/master/crudini#L375

Unfortunatley think thats where my python knowedge dries up. Gonna have to attempt another solution to dealing with ini files :(

pixelb commented 2 years ago

Addressed in commit 0f2c0b03