From c2d857c585d86f1286ad2b2947d3b8ae450304a8 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Sun, 10 Nov 2013 12:25:59 -1000 Subject: [PATCH] Remove Secure File Overwrite Support Closes #42 --- README.md | 2 +- vcr/persisters/filesystem.py | 15 ++------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 480a988..0243997 100644 --- a/README.md +++ b/README.md @@ -257,7 +257,7 @@ This library is a work in progress, so the API might change on you. There are probably some [bugs](https://github.com/kevin1024/vcrpy/issues?labels=bug&page=1&state=open) floating around too. ##Changelog -* 0.4.0: Change default request recording behavior for multiple requests. If you make the same request multiple times to the same URL, the response might be different each time (maybe the response has a timestamp in it or something), so this will make the same request multiple times and save them all. Then, when you are replaying the cassette, the responses will be played back in the same order in which they were received. If you were making multiple requests to the same URL in a cassette before version 0.4.0, you might need to regenerate your cassette files. Also, removes support for the cassette.play_count counter API, since individual requests aren't unique anymore. A cassette might contain the same request several times. +* 0.4.0: Change default request recording behavior for multiple requests. If you make the same request multiple times to the same URL, the response might be different each time (maybe the response has a timestamp in it or something), so this will make the same request multiple times and save them all. Then, when you are replaying the cassette, the responses will be played back in the same order in which they were received. If you were making multiple requests to the same URL in a cassette before version 0.4.0, you might need to regenerate your cassette files. Also, removes support for the cassette.play_count counter API, since individual requests aren't unique anymore. A cassette might contain the same request several times. Also removes secure overwrite feature since that was breaking overwriting files in Windows. * 0.3.5: Fix compatibility with requests 2.x * 0.3.4: Bugfix: close file before renaming it. This fixes an issue on Windows. Thanks @smallcode for the fix. * 0.3.3: Bugfix for error message when an unreigstered custom matcher diff --git a/vcr/persisters/filesystem.py b/vcr/persisters/filesystem.py index 6a1a275..7eb6109 100644 --- a/vcr/persisters/filesystem.py +++ b/vcr/persisters/filesystem.py @@ -3,21 +3,10 @@ import os class FilesystemPersister(object): - @classmethod - def _secure_write(cls, path, contents): - """ - We'll overwrite the old version securely by writing out a temporary - version and then moving it to replace the old version - """ - dirname, filename = os.path.split(path) - fd, name = tempfile.mkstemp(dir=dirname, prefix=filename) - with os.fdopen(fd, 'w') as fout: - fout.write(contents) - os.rename(name, path) - @classmethod def write(cls, cassette_path, data): dirname, filename = os.path.split(cassette_path) if dirname and not os.path.exists(dirname): os.makedirs(dirname) - cls._secure_write(cassette_path, data) + with open(cassette_path, 'w') as f: + f.write(data)