Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6962b6e6cd3f
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cee438ee59ae
Choose a head ref
  • 3 commits
  • 2 files changed
  • 2 contributors

Commits on Jan 12, 2018

  1. Copy the full SHA
    d2505dd View commit details
  2. Implement File.lutime

    For more information, please see feature #4052.
    nomadium committed Jan 12, 2018
    Copy the full SHA
    ac44e7c View commit details

Commits on Jan 16, 2018

  1. Merge pull request #4969 from nomadium/add-file-lutime

    Add File.lutime
    enebo authored Jan 16, 2018
    Copy the full SHA
    cee438e View commit details
Showing with 57 additions and 0 deletions.
  1. +29 −0 core/src/main/java/org/jruby/RubyFile.java
  2. +28 −0 test/mri/ruby/test_file_exhaustive.rb
29 changes: 29 additions & 0 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
@@ -1147,6 +1147,35 @@ public static IRubyObject umask(ThreadContext context, IRubyObject recv, IRubyOb
return runtime.newFixnum(oldMask);
}

@JRubyMethod(required = 2, rest = true, meta = true)
public static IRubyObject lutime(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
Ruby runtime = context.runtime;
long[] atimeval = null;
long[] mtimeval = null;

if (args[0] != context.nil || args[1] != context.nil) {
atimeval = extractTimeval(context, args[0]);
mtimeval = extractTimeval(context, args[1]);
}

for (int i = 2, j = args.length; i < j; i++) {
RubyString filename = StringSupport.checkEmbeddedNulls(runtime, get_path(context, args[i]));

JRubyFile fileToTouch = JRubyFile.create(runtime.getCurrentDirectory(), filename.getUnicodeValue());

if (!fileToTouch.exists()) {
throw runtime.newErrnoENOENTError(filename.toString());
}

int result = runtime.getPosix().lutimes(fileToTouch.getAbsolutePath(), atimeval, mtimeval);
if (result == -1) {
throw runtime.newErrnoFromInt(runtime.getPosix().errno());
}
}

return runtime.newFixnum(args.length - 2);
}

@JRubyMethod(required = 2, rest = true, meta = true)
public static IRubyObject utime(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
Ruby runtime = context.runtime;
28 changes: 28 additions & 0 deletions test/mri/ruby/test_file_exhaustive.rb
Original file line number Diff line number Diff line change
@@ -640,6 +640,34 @@ def test_utime
assert_equal(t + 2, File.mtime(zerofile))
end

def test_utime_symlinkfile
return unless symlinkfile
t = Time.local(2000)
stat = File.lstat(symlinkfile)
assert_equal(1, File.utime(t, t, symlinkfile))
assert_equal(t, File.stat(regular_file).atime)
assert_equal(t, File.stat(regular_file).mtime)
end

def test_lutime
return unless File.respond_to?(:lutime)
return unless symlinkfile

r = File.stat(regular_file)
t = Time.local(2000)
File.lutime(t + 1, t + 2, symlinkfile)
rescue NotImplementedError => e
skip(e.message)
else
stat = File.stat(regular_file)
assert_equal(r.atime, stat.atime)
assert_equal(r.mtime, stat.mtime)

stat = File.lstat(symlinkfile)
assert_equal(t + 1, stat.atime)
assert_equal(t + 2, stat.mtime)
end

def test_hardlink
return unless hardlinkfile
assert_equal("file", File.ftype(hardlinkfile))