35
35
***** END LICENSE BLOCK *****/
36
36
package org .jruby ;
37
37
38
+ import jnr .constants .platform .OpenFlags ;
39
+ import jnr .posix .POSIX ;
40
+ import jnr .posix .util .Platform ;
41
+ import org .jcodings .Encoding ;
42
+ import org .jruby .anno .JRubyClass ;
43
+ import org .jruby .anno .JRubyMethod ;
44
+ import org .jruby .runtime .*;
45
+ import org .jruby .runtime .JavaSites .FileSites ;
46
+ import org .jruby .runtime .builtin .IRubyObject ;
47
+ import org .jruby .runtime .encoding .EncodingCapable ;
48
+ import org .jruby .runtime .encoding .EncodingService ;
49
+ import org .jruby .util .*;
50
+ import org .jruby .util .io .EncodingUtils ;
51
+ import org .jruby .util .io .IOEncodable ;
52
+ import org .jruby .util .io .OpenFile ;
53
+ import org .jruby .util .io .PosixShim ;
54
+
38
55
import java .io .File ;
39
56
import java .io .IOException ;
40
57
import java .io .InputStream ;
58
75
import java .util .zip .ZipEntry ;
59
76
import java .util .zip .ZipFile ;
60
77
61
- import jnr .constants .platform .OpenFlags ;
62
- import jnr .posix .POSIX ;
63
- import jnr .posix .util .Platform ;
64
- import org .jcodings .Encoding ;
65
- import org .jruby .anno .JRubyClass ;
66
- import org .jruby .anno .JRubyMethod ;
67
- import org .jruby .runtime .Block ;
68
- import org .jruby .runtime .ClassIndex ;
69
- import org .jruby .runtime .JavaSites .FileSites ;
70
- import org .jruby .runtime .ObjectAllocator ;
71
- import org .jruby .runtime .ThreadContext ;
72
- import static org .jruby .runtime .Visibility .*;
73
- import org .jruby .runtime .builtin .IRubyObject ;
74
- import org .jruby .runtime .encoding .EncodingCapable ;
75
- import org .jruby .util .ByteList ;
76
- import org .jruby .util .FileResource ;
77
- import org .jruby .util .JRubyFile ;
78
- import org .jruby .util .StringSupport ;
79
- import org .jruby .util .TypeConverter ;
80
- import org .jruby .util .io .EncodingUtils ;
81
- import org .jruby .util .io .IOEncodable ;
82
- import org .jruby .util .io .OpenFile ;
83
- import org .jruby .runtime .Helpers ;
84
- import org .jruby .runtime .encoding .EncodingService ;
85
- import org .jruby .util .io .PosixShim ;
86
-
78
+ import static org .jruby .runtime .Visibility .PRIVATE ;
87
79
import static org .jruby .util .io .EncodingUtils .vmode ;
88
80
import static org .jruby .util .io .EncodingUtils .vperm ;
89
81
@@ -1150,12 +1142,12 @@ public static IRubyObject umask(ThreadContext context, IRubyObject recv, IRubyOb
1150
1142
@ JRubyMethod (required = 2 , rest = true , meta = true )
1151
1143
public static IRubyObject utime (ThreadContext context , IRubyObject recv , IRubyObject [] args ) {
1152
1144
Ruby runtime = context .runtime ;
1153
- long [] atimeval = null ;
1154
- long [] mtimeval = null ;
1145
+ long [] atimespec = null ;
1146
+ long [] mtimespec = null ;
1155
1147
1156
- if (args [0 ] != runtime . getNil () || args [1 ] != runtime . getNil () ) {
1157
- atimeval = extractTimeval (context , args [0 ]);
1158
- mtimeval = extractTimeval (context , args [1 ]);
1148
+ if (args [0 ] != context . nil || args [1 ] != context . nil ) {
1149
+ atimespec = extractTimespec (context , args [0 ]);
1150
+ mtimespec = extractTimespec (context , args [1 ]);
1159
1151
}
1160
1152
1161
1153
for (int i = 2 , j = args .length ; i < j ; i ++) {
@@ -1167,7 +1159,7 @@ public static IRubyObject utime(ThreadContext context, IRubyObject recv, IRubyOb
1167
1159
throw runtime .newErrnoENOENTError (filename .toString ());
1168
1160
}
1169
1161
1170
- int result = runtime .getPosix ().utimes ( fileToTouch .getAbsolutePath (), atimeval , mtimeval );
1162
+ int result = runtime .getPosix ().utimensat ( 0 , fileToTouch .getAbsolutePath (), atimespec , mtimespec , 0 );
1171
1163
if (result == -1 ) {
1172
1164
throw runtime .newErrnoFromInt (runtime .getPosix ().errno ());
1173
1165
}
@@ -1554,31 +1546,31 @@ static String adjustRootPathOnWindows(Ruby runtime, String path, String dir) {
1554
1546
}
1555
1547
1556
1548
/**
1557
- * Extract a timeval (an array of 2 longs: seconds and microseconds from epoch) from
1549
+ * Extract a timespec (an array of 2 longs: seconds and nanoseconds from epoch) from
1558
1550
* an IRubyObject.
1559
1551
*/
1560
- private static long [] extractTimeval (ThreadContext context , IRubyObject value ) {
1561
- long [] timeval = new long [2 ];
1552
+ private static long [] extractTimespec (ThreadContext context , IRubyObject value ) {
1553
+ long [] timespec = new long [2 ];
1562
1554
1563
1555
if (value instanceof RubyFloat ) {
1564
- timeval [0 ] = Platform .IS_32_BIT ? RubyNumeric .num2int (value ) : RubyNumeric .num2long (value );
1556
+ timespec [0 ] = Platform .IS_32_BIT ? RubyNumeric .num2int (value ) : RubyNumeric .num2long (value );
1565
1557
double fraction = ((RubyFloat ) value ).getDoubleValue () % 1.0 ;
1566
- timeval [1 ] = (long )(fraction * 1e6 + 0.5 );
1558
+ timespec [1 ] = (long )(fraction * 1e9 + 0.5 );
1567
1559
} else if (value instanceof RubyNumeric ) {
1568
- timeval [0 ] = Platform .IS_32_BIT ? RubyNumeric .num2int (value ) : RubyNumeric .num2long (value );
1569
- timeval [1 ] = 0 ;
1560
+ timespec [0 ] = Platform .IS_32_BIT ? RubyNumeric .num2int (value ) : RubyNumeric .num2long (value );
1561
+ timespec [1 ] = 0 ;
1570
1562
} else {
1571
1563
RubyTime time ;
1572
1564
if (value instanceof RubyTime ) {
1573
1565
time = ((RubyTime ) value );
1574
1566
} else {
1575
1567
time = (RubyTime ) TypeConverter .convertToType (context , value , context .runtime .getTime (), sites (context ).to_time_checked , true );
1576
1568
}
1577
- timeval [0 ] = Platform .IS_32_BIT ? RubyNumeric .num2int (time .to_i ()) : RubyNumeric .num2long (time .to_i ());
1578
- timeval [1 ] = Platform .IS_32_BIT ? RubyNumeric .num2int (time .usec ()) : RubyNumeric .num2long (time .usec ());
1569
+ timespec [0 ] = Platform .IS_32_BIT ? RubyNumeric .num2int (time .to_i ()) : RubyNumeric .num2long (time .to_i ());
1570
+ timespec [1 ] = Platform .IS_32_BIT ? RubyNumeric .num2int (time .nsec ()) : RubyNumeric .num2long (time .nsec ());
1579
1571
}
1580
1572
1581
- return timeval ;
1573
+ return timespec ;
1582
1574
}
1583
1575
1584
1576
private void checkClosed (ThreadContext context ) {
0 commit comments