[#18186] [req] Marshal — keiju@... (Keiju ISHITSUKA)

けいじゅ@日本ラショナルソフトウェアです.

14 messages 2002/09/05
[#18190] Re: [req] Marshal — matz@... (Yukihiro Matsumoto) 2002/09/05

まつもと ゆきひろです

[#18229] Re: [ruby-cvs] rough/ext/stringio: * ruby-stringio.spec: 0.0.7, added changelog. — "U.Nakamura" <usa@...>

こんにちは、なかむら(う)です。

22 messages 2002/09/09
[#18230] Re: [ruby-cvs] rough/ext/stringio: * ruby-stringio.spec: 0.0.7, added changelog. — nobu.nakada@... 2002/09/09

なかだです。

[#18231] Re: [ruby-cvs] rough/ext/stringio: * ruby-stringio.spec: 0.0.7, added changelog. — "U.Nakamura" <usa@...> 2002/09/09

こんにちは、なかむら(う)です。

[#18232] Re: [ruby-cvs] rough/ext/stringio: * ruby-stringio.spec: 0.0.7, added changelog. — nobu.nakada@... 2002/09/09

なかだです。

[#18233] Re: [ruby-cvs] rough/ext/stringio: * ruby-stringio.spec: 0.0.7, added changelog. — "U.Nakamura" <usa@...> 2002/09/09

こんにちは、なかむら(う)です。

[#18234] Re: [ruby-cvs] rough/ext/stringio: * ruby-stringio.spec: 0.0.7, added changelog. — WATANABE Hirofumi <eban@...> 2002/09/09

わたなべです。

[#18236] Re: [ruby-cvs] rough/ext/stringio: * ruby-stringio.spec: 0.0.7, added changelog. — "U.Nakamura" <usa@...> 2002/09/09

こんにちは、なかむら(う)です。

[#18238] Re: [ruby-cvs] rough/ext/stringio: * ruby-stringio.spec: 0.0.7, added changelog. — WATANABE Hirofumi <eban@...> 2002/09/09

わたなべです。

[#18241] Re: [ruby-cvs] rough/ext/stringio: * ruby-stringio.spec: 0.0.7, added changelog. — "U.Nakamura" <usa@...> 2002/09/09

こんにちは、なかむら(う)です。

[#18285] rubicon on EWS4800 — Koji Arai <JCA02266@...>

新井です。

59 messages 2002/09/13
[#18322] Re: rubicon on EWS4800 — Koji Arai <JCA02266@...> 2002/09/21

新井です。

[#18333] Re: rubicon on EWS4800 — kjana@...4lab.to (YANAGAWA Kazuhisa) 2002/09/21

In message <20020921.152641.11483667.JCA02266@nifty.ne.jp>

[#18336] Re: rubicon on EWS4800 — nobu.nakada@... 2002/09/21

なかだです。

[#18337] Re: rubicon on EWS4800 — Tanaka Akira <akr@...17n.org> 2002/09/21

In article <200209211605.g8LG52p04564@sharui.nakada.kanuma.tochigi.jp>,

[#18338] Re: rubicon on EWS4800 — nobu.nakada@... 2002/09/21

なかだです。

[#18341] Re: rubicon on EWS4800 — Tanaka Akira <akr@...17n.org> 2002/09/21

In article <200209211628.g8LGSxp04786@sharui.nakada.kanuma.tochigi.jp>,

[#18342] Re: rubicon on EWS4800 — nobu.nakada@... 2002/09/21

なかだです。

[#18343] Re: rubicon on EWS4800 — Tanaka Akira <akr@...17n.org> 2002/09/21

In article <200209211739.g8LHdKp05495@sharui.nakada.kanuma.tochigi.jp>,

[#18345] Re: rubicon on EWS4800 — nobu.nakada@... 2002/09/22

なかだです。

[#18349] Re: rubicon on EWS4800 — Tanaka Akira <akr@...17n.org> 2002/09/22

In article <200209220415.g8M4Fkp24392@sharui.nakada.kanuma.tochigi.jp>,

[#18374] Re: [ruby-cvs] ruby/ext/tcltklib: * eval.c (ruby_run): should set toplevel visibility again here. — WATANABE Hirofumi <eban@...>

わたなべです。

20 messages 2002/09/25
[#18376] Re: [ruby-cvs] ruby/ext/tcltklib: * eval.c (ruby_run): should set toplevel visibility again here. — matz@... (Yukihiro Matsumoto) 2002/09/25

まつもと ゆきひろです

[#18377] Re: [ruby-cvs] ruby/ext/tcltklib: * eval.c (ruby_run): should set toplevel visibility again here. — nobu.nakada@... 2002/09/25

なかだです。

[#18378] Re: [ruby-cvs] ruby/ext/tcltklib: * eval.c (ruby_run): should set toplevel visibility again here. — WATANABE Hirofumi <eban@...> 2002/09/25

わたなべです。

[ruby-dev:18294] File.safe_unlink under non-DOSISH, Dir.makedirs, etc.

From: nobu.nakada@...
Date: 2002-09-16 03:29:16 UTC
List: ruby-dev #18294
なかだです。

ftools.rbのsafe_unlinkですが、削除しようとするファイル自体のパー
ミッションが関係するのは、DOSISHなシステムだけなので、他の環境
では正しく動きません。

# MacOSもかな?

それと、[ruby-talk:50306]の「なんでDirのメソッドじゃないの?」と
いうのももっともな気がするので、Dirにも同じメソッドを持たせては
どうでしょうか。

あとついでにrmdir -p相当のFile.rmdirsとか。


Index: lib/ftools.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/lib/ftools.rb,v
retrieving revision 1.8
diff -u -2 -p -w -r1.8 ftools.rb
--- lib/ftools.rb	20 Jun 2002 08:59:59 -0000	1.8
+++ lib/ftools.rb	16 Sep 2002 03:21:07 -0000
@@ -114,4 +114,6 @@ class << File
 #  unlink files safely
 
+  case RUBY_PLATFORM
+  when /mswin|mingw|bccwin|djgpp|os2|human/
   def safe_unlink(*files)
     verbose = if files[-1].is_a? String then false else files.pop end
@@ -125,5 +127,72 @@ class << File
   end
 
+    def rmdirs(*dirs)
+      verbose = if dirs[-1].is_a? String then false else dirs.pop end
+      begin
+	$stderr.print dirs.join(" "), "\n" if verbose
+	chmod 0777, *dirs
+	dirs.each(&Dir.method(:rmdir))
+      rescue
+#	STDERR.print "warning: Couldn't unlink #{files.join ' '}\n"
+      end
+    end
+  else
+    def safe_unlink(*files)
+      verbose = if files[-1].is_a? String then false else files.pop end
+      $stderr.print files.join(" "), "\n" if verbose
+      unlinked = 0
+      files.each do |file|
+	begin
+	  unlinked += (type ||= File).unlink(file)
+	rescue Errno::EISDIR
+	  type = Dir
+	  redo
+	rescue Errno::EACCES
+	  dir ||= dirname(file)
+	  begin
+	    unless (s = stat(dir)).writable?
+	      chmod(s.mode | 0200, dir)
+	      redo
+	    end
+	  rescue
+	  end
+	rescue
+	end
+      end
+      unlinked
+    end
+
+    def rmdirs(*dirs)
+      verbose = if dirs[-1].is_a? String then false else dirs.pop end
+      $stderr.print dirs.join(" "), "\n" if verbose
+      unlinked = 0
+      dirs.each do |dir|
+	next unless FileTest.directory? dir
+	until dir == "." or dir == "/"
+	  begin
+	    unlinked += Dir.rmdir(dir)
+	  rescue Errno::EACCES
+	    parent = dirname(dir)
+	    begin
+	      unless (s = stat(parent)).writable?
+		chmod(s.mode | 0200, parent)
+		redo
+	      end
+	    rescue
+	      break
+	    end
+	  rescue
+	    break
+	  end
+	  dir = parent || dirname(dir)
+	  parent = nil
+	end
+      end
+      unlinked
+    end
+  end
+
   alias rm_f safe_unlink
+  alias rmpath rmdirs
 
   def makedirs(*dirs)
@@ -164,3 +233,12 @@ class << File
 
 end
+
+class << Dir
+  define_method(:makedirs, &File.method(:makedirs))
+  alias mkpath makedirs
+
+  define_method(:rmdirs, &File.method(:rmdirs))
+  alias rmpath rmdirs
+end
+
 # vi:set sw=2:


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

In This Thread

Prev Next