Cleanup: move pl.path, pl.file and pl.dir into a single module
All of these modules have overlapping functionalities wrt to the filesystem
hello @Tieske 3 years ago I tried to refactor Penlight, probably what you are doing now. At first, thanks for the work done!
I'm agree all these 3 modules are related to file system features.
I check the dependency graph (made 3 years ago) for pl.dir and pl.file require pl.path.
pl.path was used by :
- pl.app
- pl.dir
- pl.file
- pl.test
pl.dir was used by :
- pl.file
pl.file was not used by other pl modules
I don't know if these informations are still up-to-date. maybe it should help you ... or not.
Regards,
Hello, I'd be willing to spend some time on this. I'd like to propose the following changes:
Click to expand
fs-> New moduleremove<-os.removelink<-lfs.linktouch<-lfs.touchpath<- a submodule/table holding path-related methods
file-> Removeutilsreadfile->fs.readfilereadlines->fs.readlineswritefile->fs.writefile
dirfnmatch->fs.path.matchfilter->fs.path.filtergetfiles->fs.getfilesgetdirectories->fs.getdirectoriescopyfile->fs.copyfilemovefile->fs.movefilewalk->fs.walkrmtree->fs.rmtreemakepath->fs.mkdirpclonetree->fs.clonetreedirtree->fs.dirtreegetallfiles->fs.getallfiles
pathdir-> Remove (usefs.walkorfs.dirtree)rmdir-> Remove (usefs.rmtree)mkdir->fs.mkdirattrib->fs.attriblink_attrib->fs.linkattribcurrentdir->fs.currentdirchdir->fs.chdirisdir-> Remove (usefs.attrib) (same goes for the following methods)isfile-> Removegetsize-> Removegetatime-> Removegetmtime-> Removegetctime-> Removeexists->fs.existssplitpath->fs.path.splitabspath->fs.path.abssplitext->fs.path.splitextdirname->fs.path.dirnamebasename->fs.path.basenameextension->fs.path.extnameisabs->fs.path.isabsjoin->fs.path.joinnormcase->fs.path.normcasenormpath->fs.path.normrelpath->fs.path.relexpanduser->fs.expandusertmpname->fs.tmpnamecommon_prefix->fs.path.commonprefixpackage_path->fs.path.packagepath
The idea is that fs.path (a part of fs) will contain methods which simply operate on Lua strings and don't make any system calls, while the rest of the fs module will hold the main filesystem functions.
A side discussion that we had was whether we should split the modules for Unix-like, MacOS and Windows, since the path handling is different.
- Windows has drive letters as well as network paths, uses
\instead of/as separator - MacOS and Windows are case insensitive for finding files (but retain casing when creating)
- Unix is case sensitive
@alerque probably also has some opinions on this.
I'm taking a lot of inspiration from https://github.com/truemedian/luvit-api-design, and I think the way it handles paths is pretty good: the path table/module is itself split up into path.posix and path.windows, and then function aliases for the current platform are inserted into the base path table when the library is loaded. For example, path.posix.abs and path.windows.abs are separate implementations, and path.abs is then set dynamically based on the current platform.
That's a similar approach to LuaRocks, with the overriding modules: https://github.com/luarocks/luarocks/tree/master/src/luarocks/fs
Though posix and windows alone is not enough. Mac has different behaviour because of its case insensitive treatment of files. So listing file matching README.* should return readme.md on windows and mac, but not on posix.