summaryrefslogtreecommitdiff
path: root/file.c
AgeCommit message (Collapse)Author
2018-03-02merge revision(s) 62606,62607: [Backport #14557]naruse
file.c: get rid of useless conversion * file.c (rb_file_s_stat): File.stat does not accept an IO object as trying conversion to path name string first. skip conversion to IO and try stat(2) only. file.c: realpath on special symlink * file.c (realpath_rec): fallback to symlink path when it is accessible but the link target is not actual entry on file systems. [ruby-dev:50487] [Bug #14557] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@62632 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-22[DOC] Fix indent [ci skip]kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61406 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-22[DOC] Remove unmatched parenthesis [ci skip]kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61405 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-10support 128bit ino on Windows (if available)usa
* win32/win32.c, include/ruby/win32.h (stati128, rb_{,u,l,ul}stati128): rename from stati64ns, change the type of st_ino to 64bit and added st_inohigh. * dir.c, file.c (stat, lstat): follow above changes. * file.c (rb_stat_ino): support 128bit ino. * win32/win32.c (rb_{,u,l,ul}stati128): ditto. [Feature #13731] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61096 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-04[DOC] improve rdoc formatting for links [ci skip]kazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61014 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-04support nanosec file timestamp on newer Windowsusa
Support nanosec file timestamp on Windows 8 or later. Original patches are written by kubo (Kubo Takehiro). Windows 7 and earlier also supports nanosec file timestamp, but it's too accurate than system time. so, this feature is disabled on such versions. [Feature #13726] this change also includes [Misc #13702] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61013 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-04support `File.identical?` on ReFSusa
* file.c (rb_file_idenitical_p): move Windows dependent code to win32/win32.c. * win32/win32.c (rb_w32_file_identical_p): support ReFS. see [Feature #13731] [ruby-dev:50166] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61005 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-29file.c: File.lutimenobu
* file.c (utime_internal): add File.lutime. [Feature #4052] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60933 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-28file: release GVL for access(2) syscallsnormal
Like stat(2), the access(2) syscall may take an indeterminate amount of time on slow/remote filesystems. This lets the following methods release the GVL to avoid choking the entire VM while one thread is stuck on a slow or non-responsive filesystem: - File.readable? - File.readable_real? - File.writable? - File.writable_real? - File.executable? - File.executable_real? * file.c (nogvl_eaccess): new function (nogvl_access): ditto (rb_access): new wrapper function (rb_eaccess): release GVL (rb_file_readable_real_p): use rb_access (rb_file_writable_real_p): ditto (rb_file_executable_real_p): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60925 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-26util.h: remove my_getcwdnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60908 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-24file.c: simplify eaccess(3) callersnormal
This will make future work to release GVL here simpler. * file.c (rb_eaccess): new function (rb_file_readable_p): use rb_eaccess (rb_file_writable_p): ditto (rb_file_executable_p): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-21Fix a typokazu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-20File.mkfifo releases GVLnormal
mkfifo(3) is subject to the same problems as open(2) on slow filesystems. Release the GVL and let the rest of the VM run while we call mkfifo. * file.c (nogvl_mkfifo): new function (rb_file_s_mkfifo): release GVL git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60861 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-19file.c (rb_file_s_mkfifo): use mode_t instead of intnormal
mode_t is the correct type for mkfifo(3). This fixes an oversight from r60592 which made the same change to several other functions. * file.c (rb_file_s_mkfifo): use mode_t instead of int git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60847 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-19file.c: fix 64-bit conversion warnings from r60844normal
* file.c (nogvl_truncate): cast int to VALUE before "void *" (rb_file_s_truncate): cast "void *" to VALUE before int git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-19File.readlink and rb_readlink releases GVLnormal
The `readlink' can stall on slow filesystems like `open' and `read' syscalls. Release the GVL and let the rest of the VM function while `readlink' runs. * file.c (nogvl_readlink): new function (readlink_without_gvl): ditto (rb_readlink): use readlink_without_gvl git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-18file: File#truncate and File.truncate release GVLnormal
Like IO#write and IO.open, these file operations have unpredictable performance on slow file systems. Allow other threads of the VM to proceed while they are taking place. * file.c (nogvl_truncate): extract from rb_file_s_truncate (rb_file_s_truncate): release GVL (nogvl_ftruncate): extract from rb_file_truncate (rb_file_truncate): release GVL git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60844 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-07file.c: improve docs for File#pathstomar
* file.c: [DOC] fix grammar in docs for File#path and use a stronger description than "inaccurate". git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60706 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-01file.c: infect from argumentsnobu
* file.c (rb_check_realpath_internal): infetct the result with arguments, no taint if none are tainted and cwd is not used. [ruby-core:83583] [Bug #14060] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60599 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-01revert r60596 because it cause faulure on TestFile#test_realpath_taintednessko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-01file.c: infect from argumentsnobu
* file.c (rb_check_realpath_internal): infetct the result with arguments, no taint if none are tainted and cwd is not used. [ruby-core:83583] [Bug #14060] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-31use mode_t where applicable (instead of int)normal
mode_t is the correct type for these syscalls and it can be easier-to-understand. It may also help portability to future platforms and improve type checking. * dir.c (dir_s_mkdir): use mode_t for mkdir(2) * file.c (chmod_internal): use mode_t for chmod(2) (rb_file_s_chmod): s/int/mode_t/ (lchmod_internal): ditto, deref pointer as in chmod_internal (rb_file_s_lchmod): pass pointer as in rb_file_s_chmod (rb_file_s_rename): use mode_t for umask(2) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-24file.c: fix possible alignment bugs in r60386normal
* file.c (struct apply_filename): split out from struct apply_arg * file.c (apply2files): use offsetof for flex array size calculation * file.c (apply2files): avoid redundant marking with ALLOCV [ruby-core:83535] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60408 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-24file.c: apply2files releases GVLnormal
This means File.chmod, File.lchmod, File.chown, File.lchown, File.unlink, and File.utime operations on slow filesystems no longer hold up other threads. The platform-specific utime_failed changes is compile-tested using a new UTIME_EINVAL macro This hurts performance on fast filesystem, but these methods are unlikely to be performance bottlenecks and (IMHO) avoiding pathological slowdowns and stalls are more important. benchmark results: minimum results in each 3 measurements. Execution time (sec) name trunk built file_chmod 0.591 0.801 Speedup ratio: compare with the result of `trunk' (greater is better) name built file_chmod 0.737 * file.c (UTIME_EINVAL): new macro to ease compile-testing * file.c (struct apply_arg): new struct * file.c (no_gvl_apply2files): new function * file.c (apply2files): release GVL * file.c (chmod_internal): adjust for apply2files changes * file.c (lchmod_internal): ditto * file.c (chown_internal): ditto * file.c (lchown_internal): ditto * file.c (utime_failed): ditto * file.c (utime_internal): ditto * file.c (unlink_internal): ditto [ruby-core:83200] [Feature #13996] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60386 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-23Drop to support NaCl platform.hsbt
Because NaCl and PNaCl are already sunset status. see https://bugs.chromium.org/p/chromium/issues/detail?id=239656#c160 configure.ac: Patch for this file was provided by @nobu. [Feature #14041][ruby-core:83497][fix GH-1726] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21Improve docs for `File.delete` exceptions.hsbt
https://github.com/ruby/ruby/pull/1505 Patch by @mrtazz [fix GH-1505] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-18Get rid of shadowing local variablesnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60204 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-11file.c: ALT_SEPARATOR on cygwinnobu
* file.c (file_alt_separator): define only on DOSISH platforms. File::ALT_SEPARATOR is nil on cygwin. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60159 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-03file.c: release GVL around lstat(2)normal
Like stat(2), lstat(2) can be expensive on slow filesystems and should not block other threads. There should be a minor, but not significant slowdowns in single-threaded performance similar to benchmarks around the more-portable stat(2): [ruby-core:83012] [Bug #13941] * file.c (no_gvl_lstat): new function for rb_thread_call_without_gvl (lstat_without_gvl): new wrapper to replace lstat(2) calls (rb_file_s_lstat): s/lstat/&_without_gvl/ (rb_file_lstat): ditto (rb_file_symlink_p): ditto (rb_file_s_ftype): ditto (rb_file_expand_path_internal): ditto (realpath_rec): ditto [ruby-core:83075] [Feature #13963] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60110 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-03file.c: release GVL in File.{setuid?,setgid?,sticky?}normal
* file.c (check3rdbyte): use rb_stat to release GVL git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60108 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-02use `ra` instead of new variables.ko1
* file.c (rb_file_s_rename): `struct rename_args ra` already has members which contain C ptrs. Pointed by MSP-Greg. Thanks! git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60093 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-02catch up r60088 for DOSISH.ko1
* file.c (rb_file_s_rename): src and dst are used only on DOSISH env. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60092 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-01File#rename releases GVLnormal
rename(2) requires two pathname resolution operations which can take considerable time on slow filesystems, release the GVL so operations on other threads may proceed. On fast, local filesystems, this change results in some slowdown as shown by the new benchmark. I consider the performance trade off acceptable as cases are avoided. benchmark results: minimum results in each 3 measurements. Execution time (sec) name trunk built file_rename 2.648 2.804 Speedup ratio: compare with the result of `trunk' (greater is better) name built file_rename 0.944 * file.c (no_gvl_rename): new function (rb_file_s_rename): release GVL for renames * benchmark/bm_file_rename.rb: new benchmark git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60088 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-01file.c: remove unnecessary volatile usenormal
For apply2files, all callers use the `path' VALUE for generating exceptions, so there is no need to guard it. In realpath_rec, RB_GC_GUARD is already used on link_orig. In rb_check_realpath_internal, RB_GC_GUARD is necessary and preferable (see Appendix E. of doc/extension.rdoc) * file.c (apply2files): remove unnecessary volatile (realpath_rec): ditto (rb_check_realpath_internal): ditto, and add RB_GC_GUARD git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60081 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-26Release gvl while doing (f)statnobu
At the moment rb_stat function is blocking. This patch changes the behaviour to release the gvl while waiting for OS to return from f(stat). There is behaviour impact, but not significant (times are for 100000 iterations): $ ~/releaseruby_patch/bin/ruby bench.rb Rehearsal ------------------------------------------------ File.exist?: 0.036412 0.056616 0.093028 ( 0.093075) --------------------------------------- total: 0.093028sec user system total real File.exist?: 0.042953 0.049783 0.092736 ( 0.092804) $ ~/releaseruby_no_patch/bin/ruby bench.rb Rehearsal ------------------------------------------------ File.exist?: 0.056094 0.026293 0.082387 ( 0.082389) --------------------------------------- total: 0.082387sec user system total real File.exist?: 0.037250 0.046702 0.083952 ( 0.083956) Based on the patch by Wolf <wolf@wolfsden.cz> at [ruby-core:83012], with using `rb_thread_io_blocking_region` for `fstat`. [Bug #13941] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60027 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-21file.c: rb_check_realpathnobu
* file.c (rb_check_realpath): returns real path which has no symbolic links. similar to rb_realpath except for returning Qnil if any parts did not exist. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59983 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-16file.c: [DOC] separators at dirname and basenamenobu
* file.c (rb_file_s_basename, rb_file_s_dirname): [DOC] state that trailing separators will be stripped first, like as basename(1) and dirname(1). [ruby-core:82828] [Bug #13908] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59933 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-31File#path: Raise IOError when a file is O_TMPFILEsorah
File#path for a file opened with O_TMPFILE has no meaning. A filepath returned by this method isn't guarranteed about its accuracy, but files opened with O_TMPFILE are known its recorded path has no meaning. So let them not to return any pathname. After a discussion in ruby-core, just returning Qnil makes guessing the root cause difficult. Instead, this patch makes the method to raise an error. Other consideration is calling fnctl(2) on rb_file_path, but it adds a overhead, and it's difficult to determine O_TMPFILE status after fd has been closed. [Feature #13568] * io.c(rb_file_open_generic): Set Qnil to fptr->pathv when opening a file using O_TMPFILE * file.c(rb_file_path): Raise IOError when fptr->pathv is Qnil * file.c(rb_file_path): [DOC] Update for the new behavior git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59704 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-07-29file.c: [DOC] File.mkfifonobu
* file.c (rb_file_s_mkfifo): enclose rdoc by ifdef so it will be generated properly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59443 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-08file.c: realpath in OS path encodingnobu
* dir.c (rb_dir_getwd_ospath): return cwd path in the OS path encoding. * file.c (rb_realpath_internal): work in the OS path encoding git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-03file.c: preserve encodingnobu
* file.c (path_check_0): preserve encoding of path name in warning message. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59008 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-02file.c: preserve encodingnobu
* file.c (rb_find_file_safe): preserve encoding of path in SecurityError messages. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58996 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-01load.c: convert by rb_get_path_checknobu
* load.c (rb_require_internal): convert to path name with the given safe level, without setting global safe level. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58987 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-01file.c: rb_check_funcall_default for fallback valuenobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-31Improve performance of implicit type conversionwatson1978
To convert the object implicitly, it has had two parts in convert_type() which are 1. lookink up the method's id 2. calling the method Seems that strncmp() and strcmp() in convert_type() are slightly heavy to look up the method's id for type conversion. This patch will add and use internal APIs (rb_convert_type_with_id, rb_check_convert_type_with_id) to call the method without looking up the method's id when convert the object. Array#flatten -> 19 % up Array#+ -> 3 % up [ruby-dev:50024] [Bug #13341] [Fix GH-1537] ### Before Array#flatten 104.119k (± 1.1%) i/s - 525.690k in 5.049517s Array#+ 1.993M (± 1.8%) i/s - 10.010M in 5.024258s ### After Array#flatten 124.005k (± 1.0%) i/s - 624.240k in 5.034477s Array#+ 2.058M (± 4.8%) i/s - 10.302M in 5.019328s ### Test Code require 'benchmark/ips' class Foo def to_ary [1,2,3] end end Benchmark.ips do |x| ary = [] 100.times { |i| ary << i } array = [ary] x.report "Array#flatten" do |i| i.times { array.flatten } end x.report "Array#+" do |i| obj = Foo.new i.times { array + obj } end end git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58978 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-15[DOC] File#path result can be inaccuratesorah
* file.c(rb_file_path): [DOC] Note that the pathname returned by this method can be inaccurate, for instance file gets moved, renamed, deleted or is created with File::TMPFILE option. Relates to [Feature #13568] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58734 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-17deduplicate File::NULL stringnormal
"/dev/null" is a common sight for pre-1.9.3-compatible code targeting *nix systems, so deduplicate it here, as well. * file.c (Init_File): use fstring for File::NULL git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57996 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-17deduplicate "/", ":" and "\n" stringsnormal
"/" and ":" are always statically registered in symbol.c (Init_op_tbl), and "\n" is a commonly seen in source code. * file.c (Init_File): fstring on File::SEPARATOR and File::PATH_SEPARATOR * io.c (Init_IO): fstring on rb_default_rs ("\n") git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57995 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-13file.c: join with /nobu
* file.c (rb_file_join): join using "/" always, not a constant. and fix the document. [ruby-core:79579] [Bug #13223] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57960 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-16file.c: refine messagenobu
* file.c (rb_get_path_check_convert): refine the error message when the path name contains null byte. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57336 b2dd03c8-39d4-4d8f-98ff-823fe69b080e