From: Nobuyoshi Nakada Date: 2006-09-25T14:27:43+09:00 Subject: Re: [ ruby-Bugs-5884 ] Dir.chroot and '/' Hi, At Mon, 25 Sep 2006 10:54:40 +0900, Daniel Berger (djberg96) wrote [ruby-core:08913]: > It appears that the internal function check_dirname in dir.c is > converting '/' into an empty string when you try to do > Dir.chroot('/'). > > # As root... > > irb(main):001:0> Dir.chroot(Dir.pwd) > => 0 > irb(main):002:0> Dir.chroot('/') > Errno::ENOENT: No such file or directory - > from (irb):2:in `chroot' > from (irb):2 Thank you for the report. Dir.mkdir("/") also raises ENOENT instead of EEXIST. > I don't particularly understand why we need the check_dirname() call > there at all, except perhaps for the rb_secure() call. To drop extraneous directory separators if exist. Index: file.c =================================================================== RCS file: /pub/cvs/ruby/file.c,v retrieving revision 1.251 diff -U 2 -p -u -r1.251 file.c --- file.c 10 Sep 2006 00:41:44 -0000 1.251 +++ file.c 25 Sep 2006 04:39:15 -0000 @@ -2369,7 +2369,6 @@ rb_path_last_separator(const char *path) } -#define chompdirsep rb_path_end -char * -rb_path_end(const char *path) +static char * +chompdirsep(const char *path) { while (*path) { @@ -2386,4 +2385,11 @@ rb_path_end(const char *path) } +char * +rb_path_end(const char *path) +{ + if (isdirsep(*path)) path++; + return chompdirsep(path); +} + #define BUFCHECK(cond) do {\ long bdiff = p - buf;\ -- Nobu Nakada