diff options
author | Giuseppe Scrivano <gscrivan@redhat.com> | 2014-10-22 19:52:12 +0200 |
---|---|---|
committer | Giuseppe Scrivano <gscrivan@redhat.com> | 2014-10-22 20:02:06 +0200 |
commit | 49de180191334ba1743d6d217590db3ec66309f6 (patch) | |
tree | fd5957c13df9d53cd1de3175e321efd9ddcf07ba /tests | |
parent | 0785c398b0531e8c66fd9d9263495d125221893a (diff) | |
download | ostree-49de180191334ba1743d6d217590db3ec66309f6.tar.gz |
corrupt-repo-ref.js: more aggressive file corruption
changing only a byte may not generate a corrupted file, so play very
safe and change 10 bytes.
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/corrupt-repo-ref.js | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/tests/corrupt-repo-ref.js b/tests/corrupt-repo-ref.js index b1a797da..c5f28062 100644 --- a/tests/corrupt-repo-ref.js +++ b/tests/corrupt-repo-ref.js @@ -72,17 +72,26 @@ let loosePath = repo.get_path().resolve_relative_path('objects/' + objectToCorru let iostream = loosePath.open_readwrite(null); let info = iostream.query_info('standard::size', null); let size = info.get_size(); -let byteOffsetToCorrupt = GLib.random_int_range(0, size); -iostream.seek(byteOffsetToCorrupt, GLib.SeekType.SET, null); let datain = Gio.DataInputStream.new(iostream.get_input_stream()); let dataout = Gio.DataOutputStream.new(iostream.get_output_stream()); -let inbyte = datain.read_byte(null); -let outbyte = (inbyte + 1) % 255; -dataout.put_byte(outbyte, null); +let bytesToChange = 10; +let status = ""; +var bytesChanged = {} +for (i = 0; i < bytesToChange; i++) { + let byteOffsetToCorrupt; + do { + byteOffsetToCorrupt = GLib.random_int_range(0, size); + } while (byteOffsetToCorrupt in bytesChanged); + iostream.seek(byteOffsetToCorrupt, GLib.SeekType.SET, null); + let inbyte = datain.read_byte(null); + let outbyte = (inbyte + 1) % 255; + dataout.put_byte(outbyte, null); + bytesChanged[byteOffsetToCorrupt] = byteOffsetToCorrupt; + status += "Changed byte offset " + byteOffsetToCorrupt + " from " + inbyte + " to " + outbyte + "\n"; +} dataout.flush(null); iostream.close(null); -let status = "Changed byte offset " + byteOffsetToCorrupt + " from " + inbyte + " to " + outbyte; -print(status); +print(status); let successFile = Gio.File.new_for_path('corrupted-status.txt'); successFile.replace_contents(status, null, false, 0, null); |