File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ Install from GitHub::
24
24
Status
25
25
------
26
26
27
- Highly experimental, pre-alpha. Bug reports and pull requests very welcome.
27
+ Highly experimental, pre-alpha. Bug reports and pull requests welcome.
28
28
29
29
Design goals
30
30
------------
Original file line number Diff line number Diff line change @@ -510,13 +510,24 @@ cdef class PersistentChunk(BaseChunk):
510
510
raise RuntimeError (' error during blosc compression: %d ' % ret)
511
511
512
512
cdef void write(self , bytes data):
513
+
513
514
# N.B., write to a temporary file then move into place to avoid data
514
- # corruption due to errors during write leaving partially written files
515
- tmp = tempfile.mktemp(suffix = ' .partial' , prefix = self ._basename + ' .' ,
516
- dir = self ._dirname)
517
- with open (tmp, ' wb' ) as f:
515
+ # corruption that could happen if errors during write leave partially
516
+ # written files
517
+
518
+ temp_path = None
519
+
520
+ # write to temporary file
521
+ with tempfile.NamedTemporaryFile(mode = ' wb' , delete = False ,
522
+ dir = self ._dirname,
523
+ prefix = self ._basename + ' .' ,
524
+ suffix = ' .partial' ) as f:
518
525
f.write(data)
519
- os.replace(tmp, self ._path)
526
+ temp_path = f.name
527
+
528
+ # move temporary file into place
529
+ if temp_path is not None :
530
+ os.replace(temp_path, self ._path)
520
531
521
532
cdef void put(self , char * source):
522
533
cdef:
You can’t perform that action at this time.
0 commit comments