ziperu 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +36 -0
- data/Cargo.lock +1 -1
- data/ext/ziperu/Cargo.toml +1 -1
- data/ext/ziperu/src/lib.rs +1 -0
- data/ext/ziperu/src/place.rs +27 -1
- data/ext/ziperu/src/writer.rs +56 -8
- data/lib/ziperu/dirtyable.rb +9 -2
- data/lib/ziperu/entry.rb +25 -4
- data/lib/ziperu/entry_set.rb +12 -0
- data/lib/ziperu/file/commit.rb +4 -1
- data/lib/ziperu/file.rb +3 -0
- data/lib/ziperu/ioextras.rb +11 -0
- data/lib/ziperu/output_stream.rb +27 -14
- data/lib/ziperu/size_estimator.rb +2 -1
- data/lib/ziperu/tar/writer.rb +1 -2
- data/lib/ziperu/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8a499056593773ba9423985aac1f94849369c66eb21028beddbe3b3b1923a506
|
|
4
|
+
data.tar.gz: 6a983144dc7bb0ea1323da3428332cdf9008cfb4e7d6a14c0b8c425d01354d53
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f40e92f6ade4897d74aa470a01b9ff9d445ce147ed36e4813cc4374d5144a856d3af048dfbe528976b793aca7273374c99df9a25093cf89caade0a7d3e2fb3ca
|
|
7
|
+
data.tar.gz: 1d4d07ae6b193a4d7538c1f688c4d5b97a0c3f6f1c734142fb6bbf2053d7e11e213f699484053816c13bd62f4e832996b9ef531e68d6e91eaeb93e886ab10eb1
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.1 (2026-12-06)
|
|
4
|
+
|
|
5
|
+
Fixed:
|
|
6
|
+
|
|
7
|
+
- An archive opened with `write: false` could still be rewritten: a
|
|
8
|
+
setter on one of its entries (`entry.comment = ...`, `name=`, `time=`
|
|
9
|
+
and the rest) marked it changed, and closing the archive wrote it out.
|
|
10
|
+
Those setters now raise `Ziperu::Error` at the call, and a commit of a
|
|
11
|
+
read-only archive writes nothing whatever was changed.
|
|
12
|
+
- `OutputStream#rollback_entry`, refused because the entry's first bytes
|
|
13
|
+
had already gone out on a stream that cannot seek, dropped what was
|
|
14
|
+
still buffered for that entry, so the archive came out with the entry
|
|
15
|
+
short. The data is kept.
|
|
16
|
+
- `File#rename` to a name the entry cannot take (absolute, too long)
|
|
17
|
+
raised only after the entry had been removed, and the next commit
|
|
18
|
+
wrote the archive without it. The name is checked first.
|
|
19
|
+
- An append in place that failed while the archive was being finished
|
|
20
|
+
(an archive comment too long, a disk that filled, a read-back that
|
|
21
|
+
failed) left the archive without a central directory: the saved one
|
|
22
|
+
was let go before the last steps. It is now kept until they are done
|
|
23
|
+
and put back if any fails, and `OutputStream.open(append: true)`
|
|
24
|
+
abandons the append when closing raises.
|
|
25
|
+
- `OutputStream.estimated_size` with `write_zip64_support: :always`
|
|
26
|
+
came out short by the zip64 fields every entry is then written with.
|
|
27
|
+
The estimator and the writer now ask the same question.
|
|
28
|
+
- Committing an append re-read the appended entries in time that grew
|
|
29
|
+
with the square of the archive: 1,000 entries appended to an archive
|
|
30
|
+
of 60,000 took 2.5 s to commit and now take 0.35 s.
|
|
31
|
+
- A file whose name was within about twenty bytes of the 255 a name may
|
|
32
|
+
have could be extracted but not replaced: the replacement is written
|
|
33
|
+
beside it under a longer name, which the file system refused (`File
|
|
34
|
+
name too long`). That stopped a tar archive listing such a name twice,
|
|
35
|
+
an extraction with `on_exists: :overwrite` over such a file, and
|
|
36
|
+
`Ziperu::Tar.create` to an archive so named. The name written beside
|
|
37
|
+
is now cut to fit. Found by the nightly tar fuzzer.
|
|
38
|
+
|
|
3
39
|
## 0.4.0 (2026-11-21)
|
|
4
40
|
|
|
5
41
|
Added:
|
data/Cargo.lock
CHANGED
data/ext/ziperu/Cargo.toml
CHANGED
data/ext/ziperu/src/lib.rs
CHANGED
|
@@ -141,6 +141,7 @@ fn init(ruby: &Ruby) -> Result<(), Error> {
|
|
|
141
141
|
writer.define_method("comment=", method!(writer::Writer::set_comment, 1))?;
|
|
142
142
|
writer.define_method("rollback_entry", method!(writer::Writer::rollback_entry, 0))?;
|
|
143
143
|
writer.define_method("finish", method!(writer::Writer::finish, 0))?;
|
|
144
|
+
writer.define_method("fail_finish", method!(writer::Writer::fail_finish, 0))?;
|
|
144
145
|
writer.define_method("closed?", method!(writer::Writer::is_closed, 0))?;
|
|
145
146
|
|
|
146
147
|
Ok(())
|
data/ext/ziperu/src/place.rs
CHANGED
|
@@ -114,6 +114,22 @@ impl Beneath {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
/// The longest a file's name may be, in bytes, on the file systems an
|
|
118
|
+
/// archive is extracted to.
|
|
119
|
+
const NAME_MAX: usize = 255;
|
|
120
|
+
|
|
121
|
+
/// A hidden name for the file that will replace `leaf`. It says which
|
|
122
|
+
/// file it is for as far as there is room: a name near the limit leaves
|
|
123
|
+
/// none for what is added, and has its end cut.
|
|
124
|
+
fn staged_name(leaf: &str, pid: u32, n: u64) -> String {
|
|
125
|
+
let tail = format!(".ziperu-{pid}-{n}");
|
|
126
|
+
let mut end = leaf.len().min(NAME_MAX.saturating_sub(1 + tail.len()));
|
|
127
|
+
while !leaf.is_char_boundary(end) {
|
|
128
|
+
end -= 1;
|
|
129
|
+
}
|
|
130
|
+
format!(".{}{tail}", &leaf[..end])
|
|
131
|
+
}
|
|
132
|
+
|
|
117
133
|
impl Place {
|
|
118
134
|
/// Creates `leaf`, which must not exist yet.
|
|
119
135
|
pub(crate) fn create_new(&self, leaf: &str) -> io::Result<File> {
|
|
@@ -133,7 +149,7 @@ impl Place {
|
|
|
133
149
|
static COUNTER: AtomicU64 = AtomicU64::new(0);
|
|
134
150
|
loop {
|
|
135
151
|
let n = COUNTER.fetch_add(1, Ordering::Relaxed);
|
|
136
|
-
let staged =
|
|
152
|
+
let staged = staged_name(leaf, std::process::id(), n);
|
|
137
153
|
match self.create_new(&staged) {
|
|
138
154
|
Ok(file) => return Ok((staged, file)),
|
|
139
155
|
Err(e) if e.kind() == io::ErrorKind::AlreadyExists => {}
|
|
@@ -314,6 +330,16 @@ mod tests {
|
|
|
314
330
|
use std::io::Write;
|
|
315
331
|
use std::os::unix::fs::symlink;
|
|
316
332
|
|
|
333
|
+
#[test]
|
|
334
|
+
fn a_staged_name_fits_whatever_it_is_for() {
|
|
335
|
+
assert_eq!(staged_name("a.txt", 7, 3), ".a.txt.ziperu-7-3");
|
|
336
|
+
for leaf in ["n".repeat(255), "é".repeat(127), "n".repeat(237)] {
|
|
337
|
+
let staged = staged_name(&leaf, u32::MAX, u64::MAX);
|
|
338
|
+
assert!(staged.len() <= NAME_MAX, "{} bytes", staged.len());
|
|
339
|
+
assert!(staged.ends_with(&format!(".ziperu-{}-{}", u32::MAX, u64::MAX)));
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
317
343
|
fn scratch(name: &str) -> PathBuf {
|
|
318
344
|
let dir = std::env::temp_dir().join(format!("ziperu-place-{name}-{}", std::process::id()));
|
|
319
345
|
let _ = fs::remove_dir_all(&dir);
|
data/ext/ziperu/src/writer.rs
CHANGED
|
@@ -133,6 +133,19 @@ struct Append {
|
|
|
133
133
|
tail_start: u64,
|
|
134
134
|
/// Its bytes, to the end of the file.
|
|
135
135
|
tail: Vec<u8>,
|
|
136
|
+
/// The archive, for when the writer that held it open is gone.
|
|
137
|
+
path: String,
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
impl Append {
|
|
141
|
+
/// Puts the archive back as it was, through its path: what there is
|
|
142
|
+
/// to do once finishing has failed and taken the writer with it.
|
|
143
|
+
fn restore(&self) -> io::Result<()> {
|
|
144
|
+
let mut file = fs::OpenOptions::new().write(true).open(&self.path)?;
|
|
145
|
+
file.seek(SeekFrom::Start(self.tail_start))?;
|
|
146
|
+
file.write_all(&self.tail)?;
|
|
147
|
+
file.set_len(self.tail_start + self.tail.len() as u64)
|
|
148
|
+
}
|
|
136
149
|
}
|
|
137
150
|
|
|
138
151
|
struct State {
|
|
@@ -142,6 +155,9 @@ struct State {
|
|
|
142
155
|
count: usize,
|
|
143
156
|
crypto: Crypto,
|
|
144
157
|
append: Option<Append>,
|
|
158
|
+
/// Makes `finish` fail once the archive is written: see
|
|
159
|
+
/// `Writer::fail_finish`.
|
|
160
|
+
fail_finish: bool,
|
|
145
161
|
}
|
|
146
162
|
|
|
147
163
|
/// Writes below this many bytes keep the GVL (see `Writer::write`).
|
|
@@ -259,6 +275,7 @@ impl Writer {
|
|
|
259
275
|
base,
|
|
260
276
|
tail_start,
|
|
261
277
|
tail,
|
|
278
|
+
path,
|
|
262
279
|
});
|
|
263
280
|
}
|
|
264
281
|
Ok(out)
|
|
@@ -856,17 +873,40 @@ impl Writer {
|
|
|
856
873
|
/// what a streamed entry came to.
|
|
857
874
|
pub fn finish(ruby: &Ruby, rb_self: &Self) -> Result<(Option<RString>, RArray), Error> {
|
|
858
875
|
rb_self.check_broken(ruby)?;
|
|
859
|
-
let (zip, crypto,
|
|
876
|
+
let (zip, crypto, append, fail) = {
|
|
860
877
|
let mut state = rb_self.borrow(ruby)?;
|
|
861
878
|
let zip = state.zip.take().ok_or_else(|| closed_error(ruby))?;
|
|
862
|
-
let
|
|
863
|
-
(
|
|
879
|
+
let append = state.append.take();
|
|
880
|
+
(
|
|
881
|
+
zip,
|
|
882
|
+
std::mem::take(&mut state.crypto),
|
|
883
|
+
append,
|
|
884
|
+
state.fail_finish,
|
|
885
|
+
)
|
|
864
886
|
};
|
|
865
|
-
let
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
887
|
+
let base = append.as_ref().map_or(0, |a| a.base);
|
|
888
|
+
// The old central directory is kept until all of this has worked:
|
|
889
|
+
// writing the new one, reading the archive back, patching headers.
|
|
890
|
+
// A failure anywhere in it has dropped the writer, and with it the
|
|
891
|
+
// only handle, by the time it is known; the archive is put back
|
|
892
|
+
// through its path.
|
|
893
|
+
let outcome = maybe_without_gvl(rb_self.needs_gvl(), || {
|
|
894
|
+
let done = match zip {
|
|
895
|
+
Zip::Seekable(zip) => finish_seekable(zip, crypto),
|
|
896
|
+
Zip::Stream(zip, stats) => finish_stream(zip, *stats),
|
|
897
|
+
};
|
|
898
|
+
let done = match done {
|
|
899
|
+
Ok(_) if fail => Err(ZipError::Io(io::Error::other("finishing was made to fail"))),
|
|
900
|
+
other => other,
|
|
901
|
+
};
|
|
902
|
+
if done.is_err() {
|
|
903
|
+
if let Some(append) = &append {
|
|
904
|
+
let _ = append.restore();
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
done
|
|
908
|
+
});
|
|
909
|
+
let (sink, stats) = outcome.rb(ruby)?;
|
|
870
910
|
let bytes = match sink {
|
|
871
911
|
Sink::File(_) | Sink::Ruby(_) => None,
|
|
872
912
|
Sink::Memory(c) => Some(ruby.str_from_slice(&c.into_inner())),
|
|
@@ -878,6 +918,13 @@ impl Writer {
|
|
|
878
918
|
Ok((bytes, out))
|
|
879
919
|
}
|
|
880
920
|
|
|
921
|
+
/// For the tests: the next `finish` fails after it has written the
|
|
922
|
+
/// archive out, as a full disk or a failing read-back would make it.
|
|
923
|
+
pub fn fail_finish(ruby: &Ruby, rb_self: &Self) -> Result<(), Error> {
|
|
924
|
+
rb_self.borrow(ruby)?.fail_finish = true;
|
|
925
|
+
Ok(())
|
|
926
|
+
}
|
|
927
|
+
|
|
881
928
|
pub fn is_closed(&self) -> bool {
|
|
882
929
|
self.inner.try_borrow().is_ok_and(|s| s.zip.is_none())
|
|
883
930
|
}
|
|
@@ -962,6 +1009,7 @@ impl State {
|
|
|
962
1009
|
count: 0,
|
|
963
1010
|
crypto: Crypto::default(),
|
|
964
1011
|
append: None,
|
|
1012
|
+
fail_finish: false,
|
|
965
1013
|
}
|
|
966
1014
|
}
|
|
967
1015
|
}
|
data/lib/ziperu/dirtyable.rb
CHANGED
|
@@ -26,16 +26,23 @@ module Ziperu
|
|
|
26
26
|
dirty_fields << field unless dirty_fields.include?(field)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
+
# Called before a setter changes anything; raises to refuse the edit.
|
|
30
|
+
def before_edit(_field); end
|
|
31
|
+
|
|
29
32
|
module ClassMethods # :nodoc:
|
|
30
33
|
def mark_dirty(*symbols) # :nodoc:
|
|
31
|
-
# Move the original method and
|
|
34
|
+
# Move the original method, and set the dirty flag once it has
|
|
35
|
+
# taken the value: a setter that refuses one changes nothing, and
|
|
36
|
+
# must not leave the object looking edited.
|
|
32
37
|
symbols.each do |symbol|
|
|
33
38
|
orig_name = "orig_#{symbol}"
|
|
34
39
|
alias_method orig_name, symbol
|
|
35
40
|
|
|
36
41
|
define_method(symbol) do |param|
|
|
42
|
+
before_edit(symbol)
|
|
43
|
+
result = send(orig_name, param)
|
|
37
44
|
mark_dirty!(symbol)
|
|
38
|
-
|
|
45
|
+
result
|
|
39
46
|
end
|
|
40
47
|
end
|
|
41
48
|
end
|
data/lib/ziperu/entry.rb
CHANGED
|
@@ -181,6 +181,13 @@ module Ziperu
|
|
|
181
181
|
|
|
182
182
|
# Validated here rather than when the archive is written, so a bad
|
|
183
183
|
# value fails at the call site (rubyzip writes a corrupt header).
|
|
184
|
+
# Raises unless an entry may be called `name`. `File#rename` asks
|
|
185
|
+
# before it moves anything, of whatever kind of entry it holds.
|
|
186
|
+
def self.check_name(name) # :nodoc:
|
|
187
|
+
raise EntryNameError, name if name.start_with?('/')
|
|
188
|
+
raise EntryNameError if name.length > MAX_FIELD_LENGTH
|
|
189
|
+
end
|
|
190
|
+
|
|
184
191
|
def name=(name)
|
|
185
192
|
name = name.to_s
|
|
186
193
|
check_name(name)
|
|
@@ -200,6 +207,19 @@ module Ziperu
|
|
|
200
207
|
:fstype=, :gp_flags=, :name=, :size=,
|
|
201
208
|
:unix_gid=, :unix_perms=, :unix_uid=
|
|
202
209
|
|
|
210
|
+
# Every setter that edits the entry asks here first, so this is where
|
|
211
|
+
# an entry of an archive opened with `write: false` refuses.
|
|
212
|
+
def before_edit(_field = nil) # :nodoc:
|
|
213
|
+
check_editable!
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
# Raises for an entry of an archive opened read-only.
|
|
217
|
+
def check_editable! # :nodoc:
|
|
218
|
+
return unless @zipfile.kind_of?(::Ziperu::File) && @zipfile.read_only?
|
|
219
|
+
|
|
220
|
+
raise Error, "#{@zipfile.name} was opened read-only (write: false)"
|
|
221
|
+
end
|
|
222
|
+
|
|
203
223
|
# Create a new Ziperu::Entry.
|
|
204
224
|
def initialize(
|
|
205
225
|
zipfile = '', name = '', *legacy,
|
|
@@ -356,10 +376,11 @@ module Ziperu
|
|
|
356
376
|
end
|
|
357
377
|
|
|
358
378
|
def time=(value, component: :mtime)
|
|
379
|
+
check_editable!
|
|
380
|
+
value = DOSTime.from_time(value)
|
|
359
381
|
mark_dirty!(:time=)
|
|
360
382
|
extra.create(:universaltime) unless extra.member?(:universaltime) || extra.member?(:ntfs)
|
|
361
383
|
|
|
362
|
-
value = DOSTime.from_time(value)
|
|
363
384
|
setter = component.to_s.end_with?('=') ? component : "#{component}="
|
|
364
385
|
(extra[:universaltime] || extra[:ntfs]).send(setter, value)
|
|
365
386
|
@time = value if component == :mtime
|
|
@@ -389,6 +410,7 @@ module Ziperu
|
|
|
389
410
|
end
|
|
390
411
|
|
|
391
412
|
def compression_method=(method)
|
|
413
|
+
check_editable!
|
|
392
414
|
@dirty = true
|
|
393
415
|
@compression_method = (ftype == :directory ? STORED : method)
|
|
394
416
|
end
|
|
@@ -945,7 +967,7 @@ module Ziperu
|
|
|
945
967
|
# A hidden name beside `path` for its replacement, on the same file
|
|
946
968
|
# system so the rename stays one step.
|
|
947
969
|
def staging_path(path)
|
|
948
|
-
|
|
970
|
+
IOExtras.staging_path(path, rand(1 << 32).to_s(16))
|
|
949
971
|
end
|
|
950
972
|
|
|
951
973
|
# The entry's data, decompressed, into `os`.
|
|
@@ -1048,8 +1070,7 @@ module Ziperu
|
|
|
1048
1070
|
end
|
|
1049
1071
|
|
|
1050
1072
|
def check_name(name) # :nodoc:
|
|
1051
|
-
|
|
1052
|
-
raise EntryNameError if name.length > MAX_FIELD_LENGTH
|
|
1073
|
+
Entry.check_name(name)
|
|
1053
1074
|
end
|
|
1054
1075
|
|
|
1055
1076
|
def init_from_row(archive, row, zipfile, metadata_encoding, settings, owner)
|
data/lib/ziperu/entry_set.rb
CHANGED
|
@@ -51,6 +51,18 @@ module Ziperu
|
|
|
51
51
|
|
|
52
52
|
alias push <<
|
|
53
53
|
|
|
54
|
+
# Puts `fresh` in place of the entries from position `start` on,
|
|
55
|
+
# which it matches name for name: the same entries, read again. One
|
|
56
|
+
# pass, where `<<` would look each one up among all the others.
|
|
57
|
+
def replace_from(start, fresh)
|
|
58
|
+
fresh.each_with_index do |entry, i|
|
|
59
|
+
key = to_key(entry)
|
|
60
|
+
@entry_set[key] = entry if @entry_set[key].equal?(@all[start + i])
|
|
61
|
+
@all[start + i] = entry
|
|
62
|
+
end
|
|
63
|
+
self
|
|
64
|
+
end
|
|
65
|
+
|
|
54
66
|
# Adds a record read from an archive. Unlike `<<`, an earlier record
|
|
55
67
|
# of the very same name stays listed (and readable); the lookup by name
|
|
56
68
|
# finds the later one, as rubyzip's does. Names that only share a key
|
data/lib/ziperu/file/commit.rb
CHANGED
|
@@ -9,6 +9,9 @@ module Ziperu
|
|
|
9
9
|
# new archive is written beside the old one and renamed over it.
|
|
10
10
|
def commit
|
|
11
11
|
return if name.kind_of?(StringIO) || !commit_required?
|
|
12
|
+
# Whatever was changed, and however: an archive opened with
|
|
13
|
+
# `write: false` is not written.
|
|
14
|
+
return if @read_only
|
|
12
15
|
|
|
13
16
|
appended = write_changes
|
|
14
17
|
# Only now are the changes on disk; until here the entries keep
|
|
@@ -113,7 +116,7 @@ module Ziperu
|
|
|
113
116
|
|
|
114
117
|
kept = @cdir.entries.first(held)
|
|
115
118
|
kept.each { |e| e.rebind_native(native) }
|
|
116
|
-
|
|
119
|
+
@cdir.replace_from(held, fresh)
|
|
117
120
|
@native.close
|
|
118
121
|
@native = native
|
|
119
122
|
@dirty = false
|
data/lib/ziperu/file.rb
CHANGED
|
@@ -396,6 +396,9 @@ module Ziperu
|
|
|
396
396
|
check_writable!
|
|
397
397
|
found_entry = get_entry(entry)
|
|
398
398
|
new_name = new_name.to_path if new_name.respond_to?(:to_path)
|
|
399
|
+
# Before anything is removed: a name the entry cannot take must
|
|
400
|
+
# leave it, and an entry of that name, where they were.
|
|
401
|
+
Entry.check_name(new_name.to_s)
|
|
399
402
|
check_entry_exists(new_name, continue_on_exists_proc, 'rename')
|
|
400
403
|
@cdir.delete(found_entry)
|
|
401
404
|
found_entry.name = new_name
|
data/lib/ziperu/ioextras.rb
CHANGED
|
@@ -45,6 +45,17 @@ module Ziperu
|
|
|
45
45
|
::Ziperu::RUNNING_ON_WINDOWS && name.to_s.include?(':')
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
+
# A hidden name beside `path` for the file that will replace it, in
|
|
49
|
+
# the same directory so that the rename is one step. `tag` tells
|
|
50
|
+
# one from another. The name says which file it is for as far as
|
|
51
|
+
# the 255 bytes a name may have allow.
|
|
52
|
+
def staging_path(path, tag)
|
|
53
|
+
dir, base = ::File.split(path)
|
|
54
|
+
tail = ".ziperu-#{::Process.pid}-#{tag}"
|
|
55
|
+
kept = base.byteslice(0, 254 - tail.bytesize).scrub('')
|
|
56
|
+
::File.join(dir, ".#{kept}#{tail}")
|
|
57
|
+
end
|
|
58
|
+
|
|
48
59
|
# Whether the native core can take `str` as a name or path: it wants
|
|
49
60
|
# valid UTF-8.
|
|
50
61
|
def native_text?(str)
|
data/lib/ziperu/output_stream.rb
CHANGED
|
@@ -102,16 +102,18 @@ module Ziperu
|
|
|
102
102
|
return new(file_name, **opts) unless block_given?
|
|
103
103
|
|
|
104
104
|
zos = new(file_name, stream: false, **opts)
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
105
|
+
begin
|
|
106
|
+
result = yield zos
|
|
107
|
+
# Inside the handler too: an append is not over, and can still
|
|
108
|
+
# fail (a comment too long, a disk that fills), until the
|
|
109
|
+
# archive is closed.
|
|
110
|
+
zos.close
|
|
111
|
+
rescue Exception # rubocop:disable Lint/RescueException
|
|
112
|
+
# The archive is abandoned: the entries written so far must
|
|
113
|
+
# not learn offsets and sizes from it.
|
|
114
|
+
zos.abort
|
|
115
|
+
raise
|
|
116
|
+
end
|
|
115
117
|
result
|
|
116
118
|
end
|
|
117
119
|
|
|
@@ -258,12 +260,14 @@ module Ziperu
|
|
|
258
260
|
entry = @current_entry
|
|
259
261
|
raise Error, 'there is no entry being written to take back' if entry.nil? || !@written.last.equal?(entry)
|
|
260
262
|
|
|
261
|
-
discard_writes
|
|
262
263
|
if @deferred
|
|
263
264
|
@deferred = nil
|
|
264
265
|
else
|
|
265
266
|
@writer.rollback_entry
|
|
266
267
|
end
|
|
268
|
+
# Only now: where the entry cannot be taken back (its first bytes
|
|
269
|
+
# have gone out on a stream) what was written to it is still owed.
|
|
270
|
+
discard_writes
|
|
267
271
|
@written.pop
|
|
268
272
|
@stream_names&.delete(entry.name.b)
|
|
269
273
|
@current_entry = nil
|
|
@@ -471,6 +475,17 @@ module Ziperu
|
|
|
471
475
|
self
|
|
472
476
|
end
|
|
473
477
|
|
|
478
|
+
# Whether a file entry under 4 GiB, with no `zip64:` of its own, is
|
|
479
|
+
# written zip64-ready under `settings`. `unsized` is true for one
|
|
480
|
+
# whose size is not known up front (or that already has the field).
|
|
481
|
+
# The size estimator asks the same question, so the two cannot differ.
|
|
482
|
+
def self.zip64_file?(settings, suppressed: false, unsized: false) # :nodoc:
|
|
483
|
+
return true if settings.write_zip64_support == :always && !suppressed
|
|
484
|
+
return false if suppressed || !settings.write_zip64_support
|
|
485
|
+
|
|
486
|
+
unsized
|
|
487
|
+
end
|
|
488
|
+
|
|
474
489
|
private
|
|
475
490
|
|
|
476
491
|
# Hands the gathered small writes (see `<<`) to the native writer.
|
|
@@ -642,10 +657,8 @@ module Ziperu
|
|
|
642
657
|
return true if entry.size >= ZIP64_SIZE_LIMIT || entry.compressed_size >= ZIP64_SIZE_LIMIT
|
|
643
658
|
return false unless entry.file?
|
|
644
659
|
return entry.zip64 unless entry.zip64.nil?
|
|
645
|
-
return true if @settings.write_zip64_support == :always && !suppressed
|
|
646
|
-
return false if suppressed || !@settings.write_zip64_support
|
|
647
660
|
|
|
648
|
-
entry.zip64? || !entry.size_known?
|
|
661
|
+
self.class.zip64_file?(@settings, suppressed: suppressed, unsized: entry.zip64? || !entry.size_known?)
|
|
649
662
|
end
|
|
650
663
|
end
|
|
651
664
|
end
|
|
@@ -90,7 +90,8 @@ module Ziperu
|
|
|
90
90
|
def add_file(name, size, compressed_size)
|
|
91
91
|
fields = default_fields
|
|
92
92
|
name = name.to_s.b
|
|
93
|
-
large = size >= ZIP64_THRESHOLD || compressed_size >= ZIP64_THRESHOLD
|
|
93
|
+
large = size >= ZIP64_THRESHOLD || compressed_size >= ZIP64_THRESHOLD ||
|
|
94
|
+
OutputStream.zip64_file?(@settings)
|
|
94
95
|
offset_large = @data >= ZIP64_THRESHOLD
|
|
95
96
|
@entries += 1
|
|
96
97
|
# The local header, with a zip64 extra for a large entry; the data;
|
data/lib/ziperu/tar/writer.rb
CHANGED
|
@@ -240,8 +240,7 @@ module Ziperu
|
|
|
240
240
|
# A name beside the archive's own, in the same directory so that the
|
|
241
241
|
# rename at the end cannot cross a file system.
|
|
242
242
|
def staging_path
|
|
243
|
-
|
|
244
|
-
::File.join(dir, ".#{base}.ziperu-#{::Process.pid}-#{::SecureRandom.hex(8)}")
|
|
243
|
+
IOExtras.staging_path(@path, ::SecureRandom.hex(8))
|
|
245
244
|
end
|
|
246
245
|
|
|
247
246
|
# A name as the archive takes it: not empty, no NUL, and no slash at
|
data/lib/ziperu/version.rb
CHANGED