Skip to content

Commit 1bf6086

Browse files
committedMar 15, 2018
Fall back on utime when utimensat is not available. Fixes #5075
1 parent 2a1313c commit 1bf6086

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed
 

Diff for: ‎core/src/main/java/org/jruby/RubyFile.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.jcodings.Encoding;
4242
import org.jruby.anno.JRubyClass;
4343
import org.jruby.anno.JRubyMethod;
44+
import org.jruby.exceptions.RaiseException;
4445
import org.jruby.runtime.*;
4546
import org.jruby.runtime.JavaSites.FileSites;
4647
import org.jruby.runtime.builtin.IRubyObject;
@@ -1159,7 +1160,19 @@ public static IRubyObject utime(ThreadContext context, IRubyObject recv, IRubyOb
11591160
throw runtime.newErrnoENOENTError(filename.toString());
11601161
}
11611162

1162-
int result = runtime.getPosix().utimensat(0, fileToTouch.getAbsolutePath(), atimespec, mtimespec, 0);
1163+
int result;
1164+
1165+
try {
1166+
result = runtime.getPosix().utimensat(0, fileToTouch.getAbsolutePath(), atimespec, mtimespec, 0);
1167+
} catch (RaiseException re) {
1168+
if (re.getException().getMetaClass() == runtime.getNotImplementedError()) {
1169+
// fall back on utimes
1170+
result = runtime.getPosix().utimes(fileToTouch.getAbsolutePath(), atimespec, mtimespec);
1171+
} else {
1172+
throw re;
1173+
}
1174+
}
1175+
11631176
if (result == -1) {
11641177
throw runtime.newErrnoFromInt(runtime.getPosix().errno());
11651178
}

0 commit comments

Comments
 (0)
Please sign in to comment.