Skip to content

Commit fd4035e

Browse files
committed
Set writer modification time to now by default
CRuby does this lazily on first write, when it sets up the headers, but that laziness is handled inside jzlib for us. Just set it and if it is updated by user it will be updated in the writer. Fixes #7879, which led to tests being skipped in rack/rack#2182.
1 parent 890c9c7 commit fd4035e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

core/src/main/java/org/jruby/ext/zlib/JZlibRubyGzipWriter.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ private int processLevel(int argc, IRubyObject[] args, Ruby runtime) {
134134
return level;
135135
}
136136

137-
private IRubyObject initializeCommon(IRubyObject stream, int level) {
138-
realIo = (RubyObject) stream;
137+
private IRubyObject initializeCommon(ThreadContext context, IRubyObject stream, int level) {
138+
Ruby runtime = context.runtime;
139+
realIo = stream;
139140
try {
140141
// the 15+16 here is copied from a Deflater default constructor
141142
Deflater deflater = new Deflater(level, 15+16, false);
@@ -158,9 +159,15 @@ public void write(byte[] bytes, int off, int len) throws IOException {
158159
};
159160

160161
io = new GZIPOutputStream(ioOutputStream, deflater, 512, false);
162+
163+
// set mtime to current time in case it is never updated
164+
long now = System.currentTimeMillis();
165+
this.mtime = RubyTime.newTime(runtime, now);
166+
io.setModifiedTime(now / 1000);
167+
161168
return this;
162169
} catch (IOException ioe) {
163-
throw getRuntime().newIOErrorFromException(ioe);
170+
throw runtime.newIOErrorFromException(ioe);
164171
}
165172
}
166173

0 commit comments

Comments
 (0)