Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1ff2f21

Browse files
committed
Removed seeks beyond eof (MW doesn't support them)
1 parent e99c824 commit 1ff2f21

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

Mac/Lib/dbmac.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ def __init__(self, file):
2929
self._dirfile = file + '.dir'
3030
self._datfile = file + '.dat'
3131
self._bakfile = file + '.bak'
32+
# Mod by Jack: create data file if needed
33+
try:
34+
f = _open(self._datfile, 'r')
35+
except IOError:
36+
f = _open(self._datfile, 'w')
37+
f.close()
3238
self._update()
3339

3440
def _update(self):
@@ -67,8 +73,13 @@ def _addval(self, val):
6773
f = _open(self._datfile, 'rb+')
6874
f.seek(0, 2)
6975
pos = f.tell()
70-
pos = ((pos + _BLOCKSIZE - 1) / _BLOCKSIZE) * _BLOCKSIZE
71-
f.seek(pos)
76+
## Does not work under MW compiler
77+
## pos = ((pos + _BLOCKSIZE - 1) / _BLOCKSIZE) * _BLOCKSIZE
78+
## f.seek(pos)
79+
npos = ((pos + _BLOCKSIZE - 1) / _BLOCKSIZE) * _BLOCKSIZE
80+
f.write('\0'*(npos-pos))
81+
pos = npos
82+
7283
f.write(val)
7384
f.close()
7485
return (pos, len(val))

0 commit comments

Comments
 (0)