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

Pathname#write does not work #13

Open
mikz opened this issue Oct 1, 2014 · 6 comments
Open

Pathname#write does not work #13

mikz opened this issue Oct 1, 2014 · 6 comments
Assignees

Comments

@mikz
Copy link
Contributor

mikz commented Oct 1, 2014

Pathname is implemented in C and does not reflect MemFS filesystem.

@simonc
Copy link
Owner

simonc commented Oct 1, 2014

Hi @mikz, thanks for your feedback. Could you provide a code example that could help reproduce your issue? I know it's a large issue but having a starting point would be cool :)

@mikz
Copy link
Contributor Author

mikz commented Oct 1, 2014

require 'memfs'
MemFs.activate!
path = Pathname('folder/file')
MemFs.touch(path)
File.exist?(path.to_s) or raise 'fail'
path.write('test')

also there is another bug with Pathname, and it is:

require 'memfs'
path = Pathname('folder/file')
File.exist?(path.to_s) == File.exist?(path) or raise 'failed'
MemFs.activate!
File.exist?(path.to_s) == File.exist?(path) or raise 'failed'

It raises ArgumentError: wrong number of arguments (2 for 0)

from /Users/mikz/.rvm/gems/ruby-2.1.2/gems/memfs-0.4.1/lib/memfs/fake/directory.rb:23:in `split'

because it tries to call split('/', 2) on Pathname which does not accept params and splits to dirname and basename.

@simonc
Copy link
Owner

simonc commented Oct 1, 2014

Thank you ! I'll try to work on this issue in the coming days ;)

@simonc simonc self-assigned this Oct 5, 2014
@simonc
Copy link
Owner

simonc commented Oct 5, 2014

Ok I started to look into it and it will probably take time since I'll have to literally replace Pathname, or at least an important part of it.
I'll focus on the completion of the File class for now and come back to afterward. I already have the switching process in a branch though ;)

@awolfson
Copy link

awolfson commented Jun 7, 2016

Hey @simonc, I am curious about the status of this issue, as there are other Pathname functions that don't work, for example:

require 'pathname'
Dir.mkdir("/directory")

File.directory?("/directory")
# => true

Pathname.new("/directory").directory?
# => false

I'd be happy to help with a PR for this, somehow, although I'm afraid I'm not sure how one would go about implementing C classes in MemFs.

It could be that we just need to tack on a .map(&:to_s) somewhere like in @craigw's PR, maybe in File::Stat#directory?. I hope?!

@simonc
Copy link
Owner

simonc commented Jun 9, 2016

Hey @awolfson.

Sadly I ended up not having enough time to dig the subject. The only thing I can think of, regarding Pathname is to rewrite the entire class the same way File and Dir are rewritten in MemFs. I guess some parts of it can be delegated to the original class but every method interacting with the file system would have to be rewritten.

Regarding the .map(&:to_s) technique it may work for certain situations but not for others.

Anyway, I pushed what I had started on the pathname-support branch if anyone is interested in taking a stab at it 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants