Skip to content

Commit

Permalink
Fall back on utime when utimensat is not available. Fixes #5075
Browse files Browse the repository at this point in the history
headius committed Mar 15, 2018

Verified

This commit was signed with the committer’s verified signature.
headius Charles Oliver Nutter
1 parent 81c1bd3 commit f32fb00
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@
import org.jcodings.specific.UTF8Encoding;
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.exceptions.RaiseException;
import org.jruby.runtime.*;
import org.jruby.runtime.JavaSites.FileSites;
import org.jruby.runtime.builtin.IRubyObject;
@@ -1186,7 +1187,19 @@ public static IRubyObject utime(ThreadContext context, IRubyObject recv, IRubyOb
throw runtime.newErrnoENOENTError(filename.toString());
}

int result = runtime.getPosix().utimensat(0, fileToTouch.getAbsolutePath(), atimespec, mtimespec, 0);
int result;

try {
result = runtime.getPosix().utimensat(0, fileToTouch.getAbsolutePath(), atimespec, mtimespec, 0);
} catch (RaiseException re) {
if (re.getException().getMetaClass() == runtime.getNotImplementedError()) {
// fall back on utimes
result = runtime.getPosix().utimes(fileToTouch.getAbsolutePath(), atimespec, mtimespec);
} else {
throw re;
}
}

if (result == -1) {
throw runtime.newErrnoFromInt(runtime.getPosix().errno());
}

0 comments on commit f32fb00

Please sign in to comment.