From: IKARASHI Akira Date: 1999-03-23T18:57:44+09:00 Subject: [ruby-list:13104] Re: Dir#mv? 五十嵐です。 Yukihiro Matsumoto writes: >|ディレクトリの移動がうまくいかない(場合がある)ので、困っています。 >もしかしてファイルシステムをまたぐ場合? >それだったら UNIXの仕様 のような気がする. あ、そうです。 えっと... ftools.rb で、普通のファイルに関しては File#move中で begin rename from, to rescue syscopy from, to and unlink from end という対処をしているわけですが、ディレクトリの場合これでは サイズ0のファイルになってしまうので、ディレクトリも扱えるように するにはどうしたらいいでしょうか?という質問でした。 というメールを書いていて気づいたんですが、普通のファイルに関しても、 属性が引き継がれていないようなので、修正してみました。 *** ftools.rb.orig Tue Mar 23 18:12:00 1999 --- ftools.rb Tue Mar 23 18:37:37 1999 *************** *** 24,29 **** --- 24,32 ---- fsize = 1024 if fsize < 512 fsize = TOO_BIG if fsize > TOO_BIG + fmode = stat(from).mode + tpath = to + from = open(from, "r") from.binmode to = open(to, "w") *************** *** 47,52 **** --- 50,56 ---- to.close from.close end + chmod(fmode, tpath) ret end *************** *** 66,75 **** --- 70,86 ---- if PLATFORM =~ /djgpp|cygwin|mswin32/ and FileTest.file? to unlink to end + fstat = stat(from) begin rename from, to rescue + from_stat = stat(from) syscopy from, to and unlink from + utime(from_stat.atime, from_stat.mtime, to) + begin + chown(fstat.uid, fstat.gid, tpath) + rescue + end end end あと、修正するためにマニュアルを見ていたら File#chmod(mode, path, filename...) となっているのですが、 File#chmod(mode, filename...) ではないでしょうか? -- 五十嵐 晃(ikarashi@itlb.te.noda.sut.ac.jp)