summaryrefslogtreecommitdiff
path: root/file.c
AgeCommit message (Collapse)Author
2019-09-27Adjusted spaces [ci skip]Nobuyoshi Nakada
2019-09-05Add `File.absolute_path?` (#2198)David Rodríguez
In order to check whether a path is absolute or not in a portable way. [Feature #15868]
2019-08-29drop-in type check for rb_define_singleton_method卜部昌平
We can check the function pointer passed to rb_define_singleton_method like how we do so in rb_define_method. Doing so revealed many arity mismatches.
2019-08-29drop-in type check for rb_define_global_function卜部昌平
We can check the function pointer passed to rb_define_global_function like we do so in rb_define_method. It turns out that almost anybody is misunderstanding the API.
2019-07-30Do not always taint the result of File#pathJeremy Evans
The result should only be tainted if the path given to the method was tainted. The code to always taint the result was added in a4934a42cbb84b6679912226581c71b435671f55 (svn revision 4892) in 2003 by matz. However, the change wasn't mentioned in the commit message, and it may have been committed by accident. Skip part of a readline test that uses Reline. Reline in general would pass the test, but Reline's test mode doesn't raise a SecurityError if passing a tainted prompt and $SAFE >= 1. This was hidden earlier because File#path was always returning a tainted string. Fixes [Bug #14485]
2019-07-29Revert "Do not always taint the result of File#path"Jeremy Evans
This reverts commit 1a759bfe5d554c22571d2e6e4e5998cf06a7b98f. This fails on some operating systems.
2019-07-29Do not always taint the result of File#pathJeremy Evans
The result should only be tainted if the path given to the method was tainted. The code to always taint the result was added in a4934a42cbb84b6679912226581c71b435671f55 (svn revision 4892) in 2003 by matz. However, the change wasn't mentioned in the commit message, and it may have been committed by accident. Skip part of a readline test that uses Reline. Reline in general would pass the test, but Reline's test mode doesn't raise a SecurityError if passing a tainted prompt and $SAFE >= 1. This was hidden earlier because File#path was always returning a tainted string. Fixes [Bug #14485]
2019-07-20file.c: add a NORETURN declaration for statx_notimplementYusuke Endoh
clang complains the lack.
2019-07-14* expand tabs.git
2019-07-14Prefer `rb_error_arity` to `rb_check_arity` when it can be usedYusuke Endoh
2019-07-01Don't use native realpath(3) on SolarisJeremy Evans
CI shows it does work on Solaris 11, but does not work on Solaris 10. However, until I figure out a good way to differentiate between Solaris 10 and 11, this should get CI passing on both.
2019-07-02* expand tabs.git
2019-07-01Use realpath(3) instead of custom realpath implementation if availableJeremy Evans
This approach is simpler than the previous approach which tries to emulate realpath(3). It also performs much better on both Linux and OpenBSD on the included benchmarks. By using realpath(3), we can better integrate with system security features such as OpenBSD's unveil(2) system call. This does not use realpath(3) on Windows even if it exists, as the approach for checking for absolute paths does not work for drive letters. This can be fixed without too much difficultly, though until Windows defines realpath(3), there is no need to do so. For File.realdirpath, where the last element of the path is not required to exist, fallback to the previous approach, as realpath(3) on most operating systems requires the whole path be valid (per POSIX), and the operating systems where this isn't true either plan to conform to POSIX or may change to conform to POSIX in the future. glibc realpath(3) does not handle /path/to/file.rb/../other_file.rb paths, returning ENOTDIR in that case. Fallback to the previous code if realpath(3) returns ENOTDIR. glibc doesn't like realpath(3) usage for paths like /dev/fd/5, returning ENOENT even though the path may appear to exist in the filesystem. If ENOENT is returned and the path exists, then fall back to the default approach.
2019-06-17Update documentation for File.executable{,_real}? to mention Windows issuesJeremy Evans
Fixes [Bug #15664]
2019-06-08file.c: fix compile error with MacPorts gccNobuyoshi Nakada
With the SDK of Xcode 10.2.1, `API_AVAILABLE` and so on macros are not defined in <os/availability.h> when using a compiler other than clang (which has `__has_feature` and `__has_attribute`), but `__API_AVAILABLE` macro and so on are defined, which are also defined in <Availability.h>. I suspect this is a bug of the SDK.
2019-04-28Always mark the string returned by File.realpath as taintedJeremy Evans
This string can include elements that were not in either string passed to File.realpath, even if one of the strings is an absolute path, due to symlinks: ```ruby Dir.mkdir('b') unless File.directory?('b') File.write('b/a', '') unless File.file?('b/a') File.symlink('b', 'c') unless File.symlink?('c') path = File.realpath('c/a'.untaint, Dir.pwd.untaint) path # "/home/testr/ruby/b/a" path.tainted? # should be true, as 'b' comes from file system ``` [Bug #15803]
2019-03-23file.c: raise NotImplementedError instread of Errno::ENOSYSglass
[Misc #15615] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67338 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-22[DOC] fix markups [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-24Check stx_btime in struct statxnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-22Support File#birthtime on Linuxnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67116 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-22Unified rb_file_s_birthtimenobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67115 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-21Constifiednobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67108 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-21Path for AT_EMPTY_PATH must not be NULLnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-21Separate fstatx_without_gvl from statx_without_gvlnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67105 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-20fix r67097 with castko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-20Try statx syscallnobu
* file.c (rb_file_s_birthtime): export for pathname to check if birthtime is supported. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-20revert r67093 because it breaks testsko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67094 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-20Try statx syscallnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67093 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-19* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67089 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-19file.c: enable File.birthtime on Linuxglass
enable File.birthtime on Linux if statx(2) is available. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67088 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-23file.c: use correct integer-conversion functionmame
The return value of major() and minor() is unsigned int, not dev_t. So, UINT2NUM() is a better choice than DEVT2NUM(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65319 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-20Document File.{setuid?,setgid?,sticky?} support for IO objects [Bug #13972]aycabta
* file.c (rb_file_setuid_p): rdoc for IO object support (rb_file_sgid_p): ditto (rb_file_sticky_p): ditto * NEWS: inform users of new feature * test/file/test_file_exhaustive.rb (io_open): wrapper for bare IO object (test_suid): test for bare IO support (test_sgid): ditto (test_sticky): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65235 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-19array.c, file.c, string.c: [DOC] fix typosstomar
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65185 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-13Prefer `rb_fstring_lit` over `rb_fstring_cstr`nobu
The former states explicitly that the argument must be a literal, and can optimize away `strlen` on all compilers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-13file.c: chardev is loadablenobu
* file.c (ruby_is_fd_loadable): allow character devices to load, e.g., `ruby /dev/null` exits successfully. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63143 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-28file.c: realpath on special symlinknobu
* 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/trunk@62607 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-28file.c: get rid of useless conversionnobu
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-23[DOC] missing docs at toplevelnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-06share ruby_null_devicenobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-24ruby/ruby.h: remove unnecessary exports from C-APInormal
Needlessly exporting can reduce performance locally and increase binary size. Increasing the footprint of our C-API larger is also detrimental to our development as it encourages tighter coupling with our internals; making it harder for us to preserve compatibility. If some parts of the core codebase needs access to globals, internal.h should be used instead of anything in include/ruby/*. "Urabe, Shyouhei" <shyouhei@ruby-lang.org> wrote: > On Thu, Jan 18, 2018 at 7:33 PM, Eric Wong <normalperson@yhbt.net> wrote: > > shyouhei@ruby-lang.org wrote: > >> https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61908 > >> > >> export rb_mFConst > > > > Why are we exporting all these and making the public C-API bigger? > > If anything, we should make these static. Thanks. > > No concrete reason, except they have already been externed in 2.5. > These variables had lacked declarations so far, which resulted in their > visibility to be that of extern. The commit is just confirming the status quo. > > I'm not against to turn them into static. This reverts changes from r61910, r61909, r61908, r61907, and r61906. * transcode.c (rb_eUndefinedConversionError): make static (rb_eInvalidByteSequenceError): ditto (rb_eConverterNotFoundError): ditto * process.c (rb_mProcGID, rb_mProcUid, rb_mProcID_Syscall): ditto * file.c (rb_mFConst): ditto * error.c (rb_mWarning, rb_cWarningBuffer): ditto * enumerator.c (rb_cLazy): ditto [Misc #14381] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-19there is no guarantee that mode_t is as wide as intshyouhei
POSIX only defines mode_t to be "an integer typea", and in fact MacOS defines it to be uint16_t. We didn't have NUM2USHORT before so it did not make sense but now that we have it. Why not check apptopriately. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61950 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-14exclude flexible array size with old compilersnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61814 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-13file.c (struct apply_arg): Use FLEX_ARY_LENmame
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61807 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09internal.h: remove dependecy on ruby/encoding.hnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61713 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