Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Use FSNode's Type method instead of casting it to a File or Directory #22

Closed
schomatis opened this issue Oct 16, 2018 · 5 comments
Closed
Assignees
Labels
help wanted Seeking public contribution on this issue topic/technical debt Topic technical debt

Comments

@schomatis
Copy link
Contributor

This is actually an issue for the clients of this layer like go-ipfs.

Also, helper functions can be added like isFile() or isDir.

@schomatis schomatis added the topic/technical debt Topic technical debt label Oct 16, 2018
@schomatis schomatis self-assigned this Oct 16, 2018
@schomatis schomatis added the help wanted Seeking public contribution on this issue label Oct 16, 2018
@overbool
Copy link
Contributor

@schomatis Did you mean the follow code?

https://github.com/ipfs/go-ipfs/blob/9bf4e4145ea897ced2f9aa2087296b3beda6e941/core/commands/files.go#L455-L458

Should we add IsFile and IsDir, and then use fsn.IsFile() and fsn.IsDir instead of direct switch case about mfs.Directory and mfs.File?

@schomatis
Copy link
Contributor Author

Yes! In that particular case it's fine to use the already existing Type() and switch on those values but in others like

https://github.com/ipfs/go-ipfs/blob/9bf4e4145ea897ced2f9aa2087296b3beda6e941/core/commands/files.go#L1109

where only one type is being asserted (e.g., *mfs.Directory) we can use a (new) helper function like IsDir.

But in general what I want to avoid are references to mfs.Directory and mfs.File which are the internal implementation of the MFS directory and file and use the public API instead.

@overbool
Copy link
Contributor

@schomatis Which solution do you think is better?

  1. fsn.IsDir() / fsn.IsFile()(this should add method in FSNode interface and implement by File and Directory) .
  2. mfs.IsDir(fsn) / mfs.IsFile(fsn)

@schomatis
Copy link
Contributor Author

The second one, that way we don't need to modify the FSNode interface with helper methods.

@aschmahmann
Copy link
Contributor

This repository is no longer maintained and has been copied over to Boxo. In an effort to avoid noise and crippling in the Boxo repo from the weight of issues of the past, we are closing most issues and PRs in this repo. Please feel free to open a new issue in Boxo (and reference this issue) if resolving this issue is still critical for unblocking or improving your usecase.

You can learn more in the FAQs for the Boxo repo copying/consolidation effort.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Seeking public contribution on this issue topic/technical debt Topic technical debt
Projects
No open projects
Archived in project
Development

No branches or pull requests

3 participants