Skip to content

Commit

Permalink
Set writer modification time to now by default
Browse files Browse the repository at this point in the history
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 jruby#7879, which led to tests being skipped in
rack/rack#2182.
  • Loading branch information
headius committed Jun 4, 2024
1 parent 890c9c7 commit 51e2951
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions core/src/main/java/org/jruby/ext/zlib/JZlibRubyGzipWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public IRubyObject initialize19(ThreadContext context, IRubyObject[] args, Block
// unused; could not figure out how to get JZlib to take this right
/*int strategy = */processStrategy(argc, args);

initializeCommon(args[0], level);
initializeCommon(context, args[0], level);

ecopts(context, opt);

Expand All @@ -134,8 +134,9 @@ private int processLevel(int argc, IRubyObject[] args, Ruby runtime) {
return level;
}

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

io = new GZIPOutputStream(ioOutputStream, deflater, 512, false);

// set mtime to current time in case it is never updated
long now = System.currentTimeMillis();
this.mtime = RubyTime.newTime(runtime, now);
io.setModifiedTime(now / 1000);

return this;
} catch (IOException ioe) {
throw getRuntime().newIOErrorFromException(ioe);
throw runtime.newIOErrorFromException(ioe);
}
}

Expand Down

0 comments on commit 51e2951

Please sign in to comment.