go-uci icon indicating copy to clipboard operation
go-uci copied to clipboard

Migrate to afero

Open ski7777 opened this issue 4 years ago • 1 comments

In my main project I sometimes need to use temporary file systems, remote files systems or something else. THe current implementation was only able of using the default OS file system.

The following changes were made:

  • Add method NewTreeFromFs(afero.Fs): This creates a config tree at the base of this FS. I decided to always use the root because afero offers the method NewBasePathFs that creates a Fs object of a specific prefix in an existing Fs object.
  • Change NewTree to use NewTreeFromFs: Now the NewTree uses NewBasePathFs to create the argument for NewTreeFromFs. This way the NewTree method does not change its behavior and keeps go-uci compatible
  • All other changes were made because the file system API of afero differs a bit from ioutil.

Benefits:

  • use whatever filesystem implementation you want! Afero offers a wide range of different fs. Check out the repo: https://github.com/spf13/afero
  • make unit testing easier! using afero you can create a new config directory for each test without using the disk

If you have any questions, please ask.

Raphael

ski7777 avatar Sep 06 '20 21:09 ski7777

Sadly the unit test is not working properly yet. Maybe someone can fix this.

Thanks

ski7777 avatar Sep 06 '20 22:09 ski7777