Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standard lib FileUtils.mv takes a string or an array of strings as the src arg #40

Closed
zenspider opened this issue Jun 22, 2010 · 5 comments
Labels

Comments

@zenspider
Copy link

FileUtils.mv [file1, file2], dest

is perfectly legal. fakefs currently breaks in:

def mv(src, dest)
  if target = FileSystem.find(src)

as it isn't valid to pass an array as the arg to FileSystem.find. The error message is:

TypeError: can't convert Array into String
    project/tmp/isolate/ruby-1.8/gems/fakefs-0.2.1/lib/fakefs/file.rb:104:in `basename:'
@zenspider
Copy link
Author

A further problem is that fakefs' FileUtils.mv seems to expect dest to be an inclusive path rather than either a renamed inclusive path or a directory to move the existing file to. The following method fixes both issues:

def mv(src, dest)
  Array(src).each do |path|
    if target = FileSystem.find(path)
      d_path = if File.directory? dest then
                 File.join dest, File.basename(path)
               else
                 dest
               end
      FileSystem.add(d_path, target.entry.clone)
      FileSystem.delete(path)
    else
      raise Errno::ENOENT, path
    end
  end
end

@smtlaissezfaire
Copy link
Collaborator

I'd gladly accept a patch if some tests were included :)

@gcampbell
Copy link
Contributor

I've addressed these two issues (the array of files identified in the main issue #40, as well as directory destinations as mentioned in the comment above) as separate commits in http://github.com/gcampbell/fakefs/tree/40-mv-to-dir. The final result ends up looking pretty much like zenspider's code, except with a ternary instead of the if/else.

@wijet
Copy link
Contributor

wijet commented Dec 25, 2010

Could please merge gcambell's commits into master?

They work just fine with the latest master https://github.com/wijet/fakefs/tree/40-mv-to-dir

@gcampbell
Copy link
Contributor

FileUtils.mv can now handle an array of sources

Closed by 4e9355d. Closed by 4e9355d

davidmiani pushed a commit to davidmiani/fakefs that referenced this issue May 5, 2011
This addresses the first comment on fakefs#40.
davidmiani pushed a commit to davidmiani/fakefs that referenced this issue May 5, 2011
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants