summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-03 07:10:56 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-03 07:10:56 +0000
commitf9e9eee677e8196da7288f4ab7754ebe345d7ed9 (patch)
tree9afc0d17c7d9c39a4aa15315199939b632544147
parentf0fbf6c976b3bb5494c9740b1c6235306946f696 (diff)
* util.c, include/ruby/util.h (ruby_add_suffix): remove the function.
[Bug #5153] [ruby-core:38736] * io.c (argf_next_argv): remove the call of above function. * ext/-test-/add_suffix, test/-ext-/test_add_suffix.rb: remove the test extension module because this is only for testsing ruby_add_suffix(). * LEGAL: remove the mention about a part of util.c, because now we removed the part. * io.c (argf_next_argv): now the new filename is not guranteed to use, so should check the return value of rename(2). * test/ruby/test_argf.rb (TestArgf#test_inplace_rename_impossible): now we expect same result with other platforms on no_safe_rename platforms (=Windows). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog20
-rw-r--r--LEGAL1
-rw-r--r--ext/-test-/add_suffix/bug.c22
-rw-r--r--ext/-test-/add_suffix/depend1
-rw-r--r--ext/-test-/add_suffix/extconf.rb4
-rw-r--r--include/ruby/util.h4
-rw-r--r--io.c14
-rw-r--r--test/-ext-/test_add_suffix.rb47
-rw-r--r--test/ruby/test_argf.rb15
-rw-r--r--util.c178
10 files changed, 29 insertions, 277 deletions
diff --git a/ChangeLog b/ChangeLog
index 84a02a38a2..4cce430ad5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+Wed Aug 3 16:01:35 2011 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * util.c, include/ruby/util.h (ruby_add_suffix): remove the function.
+ [Bug #5153] [ruby-core:38736]
+
+ * io.c (argf_next_argv): remove the call of above function.
+
+ * ext/-test-/add_suffix, test/-ext-/test_add_suffix.rb: remove the test
+ extension module because this is only for testsing ruby_add_suffix().
+
+ * LEGAL: remove the mention about a part of util.c, because now we
+ removed the part.
+
+ * io.c (argf_next_argv): now the new filename is not guranteed to
+ use, so should check the return value of rename(2).
+
+ * test/ruby/test_argf.rb (TestArgf#test_inplace_rename_impossible):
+ now we expect same result with other platforms on no_safe_rename
+ platforms (=Windows).
+
Wed Aug 3 09:18:08 2011 URABE Shyouhei <shyouhei@ruby-lang.org>
* test/xmlrpc/webrick_testing.rb (WEBrick_Testing#start_server):
diff --git a/LEGAL b/LEGAL
index 0086b83665..65706459cd 100644
--- a/LEGAL
+++ b/LEGAL
@@ -148,7 +148,6 @@ util.c (partly):
REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
-util.c (partly):
win32/win32.[ch]:
You can apply the Artistic License to these files. (or GPL,
diff --git a/ext/-test-/add_suffix/bug.c b/ext/-test-/add_suffix/bug.c
deleted file mode 100644
index cd215338e0..0000000000
--- a/ext/-test-/add_suffix/bug.c
+++ /dev/null
@@ -1,22 +0,0 @@
-#include "ruby.h"
-#include "ruby/defines.h"
-#include "ruby/util.h"
-#ifndef HAVE_RUBY_ADD_SUFFIX
-#define _WIN32 1
-#include "util.c"
-#endif
-
-static VALUE
-add_suffix(VALUE self, VALUE path, VALUE suffix)
-{
- StringValueCStr(path);
- ruby_add_suffix(path, StringValueCStr(suffix));
- return path;
-}
-
-void
-Init_bug(void)
-{
- VALUE mBug = rb_define_module("Bug");
- rb_define_module_function(mBug, "add_suffix", add_suffix, 2);
-}
diff --git a/ext/-test-/add_suffix/depend b/ext/-test-/add_suffix/depend
deleted file mode 100644
index 943d0d9f21..0000000000
--- a/ext/-test-/add_suffix/depend
+++ /dev/null
@@ -1 +0,0 @@
-bug.o: $(hdrdir)/ruby/util.h $(top_srcdir)/util.c
diff --git a/ext/-test-/add_suffix/extconf.rb b/ext/-test-/add_suffix/extconf.rb
deleted file mode 100644
index bffd1550f3..0000000000
--- a/ext/-test-/add_suffix/extconf.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-unless have_func("ruby_add_suffix", "ruby/util.h")
- $INCFLAGS << " -I$(top_srcdir)"
-end
-create_makefile("-test-/add_suffix/bug")
diff --git a/include/ruby/util.h b/include/ruby/util.h
index 40f044d3cb..e82f537728 100644
--- a/include/ruby/util.h
+++ b/include/ruby/util.h
@@ -54,10 +54,6 @@ unsigned long ruby_scan_oct(const char *, size_t, size_t *);
#define scan_hex(s,l,e) ((int)ruby_scan_hex((s),(l),(e)))
unsigned long ruby_scan_hex(const char *, size_t, size_t *);
-#if defined(__CYGWIN32__) || defined(_WIN32)
-void ruby_add_suffix(VALUE str, const char *suffix);
-#endif
-
void ruby_qsort(void *, const size_t, const size_t,
int (*)(const void *, const void *, void *), void *);
diff --git a/io.c b/io.c
index 6be4e88744..d109f15c2b 100644
--- a/io.c
+++ b/io.c
@@ -35,10 +35,6 @@
# define NO_SAFE_RENAME
#endif
-#if defined(__CYGWIN__) || defined(_WIN32)
-# define NO_LONG_FNAME
-#endif
-
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(sun) || defined(_nec_ews)
# define USE_SETVBUF
#endif
@@ -6893,15 +6889,15 @@ argf_next_argv(VALUE argf)
fstat(fr, &st);
if (*ARGF.inplace) {
str = rb_str_new2(fn);
-#ifdef NO_LONG_FNAME
- ruby_add_suffix(str, ARGF.inplace);
-#else
rb_str_cat2(str, ARGF.inplace);
-#endif
#ifdef NO_SAFE_RENAME
(void)close(fr);
(void)unlink(RSTRING_PTR(str));
- (void)rename(fn, RSTRING_PTR(str));
+ if (rename(fn, RSTRING_PTR(str)) < 0) {
+ rb_warn("Can't rename %s to %s: %s, skipping file",
+ fn, RSTRING_PTR(str), strerror(errno));
+ goto retry;
+ }
fr = rb_sysopen(str, O_RDONLY, 0);
#else
if (rename(fn, RSTRING_PTR(str)) < 0) {
diff --git a/test/-ext-/test_add_suffix.rb b/test/-ext-/test_add_suffix.rb
deleted file mode 100644
index 0520baef8c..0000000000
--- a/test/-ext-/test_add_suffix.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-require 'test/unit'
-require_relative '../ruby/envutil'
-require "-test-/add_suffix/bug"
-
-class Test_AddSuffix < Test::Unit::TestCase
- Dir = "/dev/null/".freeze
- Style_1 = (Dir+"foo").freeze
-
- def test_style_0
- assert_equal("a.x.y", Bug.add_suffix("a.x", ".y"))
- end
-
- def test_style_1
- assert_equal(Style_1+".y", Bug.add_suffix(Style_1+".c", ".y"))
- suffix = ".bak".freeze
- assert_equal(Style_1+suffix, Bug.add_suffix(Style_1.dup, suffix))
- assert_equal(Style_1+suffix, Bug.add_suffix(Style_1+".bar", suffix))
- assert_equal(Style_1+".$$$", Bug.add_suffix(Style_1+suffix, suffix))
- assert_equal(Style_1+suffix, Bug.add_suffix(Style_1+".$$$", suffix))
- assert_equal(Style_1+".~~~", Bug.add_suffix(Style_1+".$$$", ".$$$"))
- assert_equal(Dir+"makefile"+suffix, Bug.add_suffix(Dir+"makefile", suffix))
- end
-
- def test_style_2
- suffix = "~"
- assert_equal(Style_1+"~", Bug.add_suffix(Style_1.dup, suffix))
- assert_equal(Style_1+".c~", Bug.add_suffix(Style_1+".c", suffix))
- assert_equal(Style_1+".c~~", Bug.add_suffix(Style_1+".c~", suffix))
- assert_equal(Style_1+"~.c~~", Bug.add_suffix(Style_1+".c~~", suffix))
- assert_equal(Style_1+"~~.c~~", Bug.add_suffix(Style_1+"~.c~~", suffix))
- assert_equal(Style_1+"~~~~~.cc~", Bug.add_suffix(Style_1+"~~~~~.ccc", suffix))
- assert_equal(Style_1+"~~~~~.$$$", Bug.add_suffix(Style_1+"~~~~~.c~~", suffix))
- assert_equal(Dir+"foo~.pas", Bug.add_suffix(Dir+"foo.pas", suffix))
- assert_equal(Dir+"makefile.~", Bug.add_suffix(Dir+"makefile", suffix))
- assert_equal(Dir+"longname.fi~", Bug.add_suffix(Dir+"longname.fil", suffix))
- assert_equal(Dir+"longnam~.fi~", Bug.add_suffix(Dir+"longname.fi~", suffix))
- assert_equal(Dir+"longnam~.$$$", Bug.add_suffix(Dir+"longnam~.fi~", suffix))
- end
-
- def test_style_3
- base = "a"*1000
- suffix = "-"+"b"*1000
- assert_equal(base+".~~~", Bug.add_suffix(base, suffix))
- assert_equal(base+".~~~", Bug.add_suffix(base+".$$$", suffix))
- assert_equal(base+".$$$", Bug.add_suffix(base+".~~~", suffix))
- end
-end
diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb
index 0e709a204d..e249c757ea 100644
--- a/test/ruby/test_argf.rb
+++ b/test/ruby/test_argf.rb
@@ -201,21 +201,14 @@ class TestArgf < Test::Unit::TestCase
t = make_tempfile
assert_in_out_err(["-", t.path], <<-INPUT) do |r, e|
- ARGF.inplace_mode = '/\\\\'
+ ARGF.inplace_mode = '/\\\\:'
while line = ARGF.gets
puts line.chomp + '.new'
end
INPUT
- if no_safe_rename
- assert_equal([], e)
- assert_equal([], r)
- assert_equal("foo.new\nbar.new\nbaz.new\n", File.read(t.path))
- File.unlink(t.path + ".~~~") rescue nil
- else
- assert_match(/Can't rename .* to .*: .*. skipping file/, e.first) #'
- assert_equal([], r)
- assert_equal("foo\nbar\nbaz\n", File.read(t.path))
- end
+ assert_match(/Can't rename .* to .*: .*. skipping file/, e.first) #'
+ assert_equal([], r)
+ assert_equal("foo\nbar\nbaz\n", File.read(t.path))
end
end
diff --git a/util.c b/util.c
index d5cf670883..45493f2855 100644
--- a/util.c
+++ b/util.c
@@ -184,184 +184,6 @@ ruby_strtoul(const char *str, char **endptr, int base)
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
-#if defined(__CYGWIN32__) || defined(_WIN32)
-/*
- * Copyright (c) 1993, Intergraph Corporation
- *
- * You may distribute under the terms of either the GNU General Public
- * License or the Artistic License, as specified in the perl README file.
- *
- * Various Unix compatibility functions and NT specific functions.
- *
- * Some of this code was derived from the MSDOS port(s) and the OS/2 port.
- *
- */
-
-
-/*
- * Suffix appending for in-place editing under MS-DOS and OS/2 (and now NT!).
- *
- * Here are the rules:
- *
- * Style 0: Append the suffix exactly as standard perl would do it.
- * If the filesystem groks it, use it. (HPFS will always
- * grok it. So will NTFS. FAT will rarely accept it.)
- *
- * Style 1: The suffix begins with a '.'. The extension is replaced.
- * If the name matches the original name, use the fallback method.
- *
- * Style 2: The suffix is a single character, not a '.'. Try to add the
- * suffix to the following places, using the first one that works.
- * [1] Append to extension.
- * [2] Append to filename,
- * [3] Replace end of extension,
- * [4] Replace end of filename.
- * If the name matches the original name, use the fallback method.
- *
- * Style 3: Any other case: Ignore the suffix completely and use the
- * fallback method.
- *
- * Fallback method: Change the extension to ".$$$". If that matches the
- * original name, then change the extension to ".~~~".
- *
- * If filename is more than 1000 characters long, we die a horrible
- * death. Sorry.
- *
- * The filename restriction is a cheat so that we can use buf[] to store
- * assorted temporary goo.
- *
- * Examples, assuming style 0 failed.
- *
- * suffix = ".bak" (style 1)
- * foo.bar => foo.bak
- * foo.bak => foo.$$$ (fallback)
- * makefile => makefile.bak
- * suffix = ".$$$" (style 1)
- * foo.$$$ => foo.~~~ (fallback)
- *
- * suffix = "~" (style 2)
- * foo.c => foo.c~
- * foo.c~ => foo.c~~
- * foo.c~~ => foo~.c~~
- * foo~.c~~ => foo~~.c~~
- * foo~~~~~.c~~ => foo~~~~~.$$$ (fallback)
- *
- * foo.pas => foo~.pas
- * makefile => makefile.~
- * longname.fil => longname.fi~
- * longname.fi~ => longnam~.fi~
- * longnam~.fi~ => longnam~.$$$
- *
- */
-
-
-static int valid_filename(const char *s);
-
-static const char suffix1[] = ".$$$";
-static const char suffix2[] = ".~~~";
-
-#define strEQ(s1,s2) (strcmp((s1),(s2)) == 0)
-
-void
-ruby_add_suffix(VALUE str, const char *suffix)
-{
- long baselen;
- long extlen = strlen(suffix);
- long slen;
- char buf[1024];
- const char *name;
- const char *ext;
- long len;
-
- name = StringValueCStr(str);
- slen = strlen(name);
- if (slen > (long)(sizeof(buf) - 1))
- rb_fatal("Cannot do inplace edit on long filename (%ld characters)",
- slen);
-
- /* Style 0 */
- rb_str_cat(str, suffix, extlen);
- if (valid_filename(RSTRING_PTR(str))) return;
-
- /* Fooey, style 0 failed. Fix str before continuing. */
- rb_str_resize(str, slen);
- name = StringValueCStr(str);
- ext = ruby_find_extname(name, &len);
-
- if (*suffix == '.') { /* Style 1 */
- if (ext) {
- if (strEQ(ext, suffix)) {
- extlen = sizeof(suffix1) - 1; /* suffix2 must be same length */
- suffix = strEQ(suffix, suffix1) ? suffix2 : suffix1;
- }
- slen = ext - name;
- }
- rb_str_resize(str, slen);
- rb_str_cat(str, suffix, extlen);
- }
- else {
- char *p = buf, *q;
- strncpy(buf, name, slen);
- if (ext)
- p += (ext - name);
- else
- p += slen;
- p[len] = '\0';
- if (suffix[1] == '\0') { /* Style 2 */
- q = (char *)ruby_find_basename(buf, &baselen, 0);
- if (len <= 3) {
- if (len == 0 && baselen >= 8 && p + 3 <= buf + sizeof(buf)) p[len++] = '.'; /* DOSISH */
- p[len] = *suffix;
- p[++len] = '\0';
- }
- else if (q && baselen < 8) {
- q += baselen;
- *q++ = *suffix;
- if (ext) {
- strncpy(q, ext, ext - name);
- q[ext - name + 1] = '\0';
- }
- else
- *q = '\0';
- }
- else if (len == 4 && p[3] != *suffix)
- p[3] = *suffix;
- else if (baselen == 8 && q[7] != *suffix)
- q[7] = *suffix;
- else
- goto fallback;
- }
- else { /* Style 3: Panic */
- fallback:
- (void)memcpy(p, !ext || strEQ(ext, suffix1) ? suffix2 : suffix1, 5);
- }
- rb_str_resize(str, strlen(buf));
- memcpy(RSTRING_PTR(str), buf, RSTRING_LEN(str));
- }
-}
-
-static int
-valid_filename(const char *s)
-{
- int fd;
-
- /*
- // It doesn't exist, so see if we can open it.
- */
-
- if ((fd = open(s, O_CREAT|O_EXCL, 0666)) >= 0) {
- close(fd);
- unlink(s); /* don't leave it laying around */
- return 1;
- }
- else if (errno == EEXIST) {
- /* if the file exists, then it's a valid filename! */
- return 1;
- }
- return 0;
-}
-#endif
-
/* mm.c */