starwing / lpath Goto Github PK
View Code? Open in Web Editor NEWa OS specified path manipulation module for Lua
License: MIT License
a OS specified path manipulation module for Lua
License: MIT License
Hi,
I installed lpath
via luarocks
on my Ubuntu 16.04 machine without a problem, but during some tests I recognized some missing functions. Here is a list from my Ubuntu machine:
{
DIR_SEP = "/",
atime = <function 1>,
attributes = <function 2>,
chdir = <function 3>,
copy = <function 4>,
ctime = <function 5>,
currentdir = <function 6>,
dir = <function 7>,
each = <function 8>,
each_impl = <function 9>,
exists = <function 10>,
foreach = <function 11>,
isdir = <function 12>,
isfile = <function 13>,
islink = <function 14>,
link = <function 15>,
mkdir = <function 16>,
move = <function 17>,
mtime = <function 18>,
remove = <function 19>,
rmdir = <function 20>,
setmode = <function 21>,
size = <function 22>,
tmpdir = <function 23>,
touch = <function 24>
}
and that one is from my notebook with Arch Linux:
{
binpath = <function 1>,
chdir = <function 2>,
cmpftime = <function 3>,
copy = <function 4>,
dir = <function 5>,
exists = <function 6>,
expandvars = <function 7>,
fnmatch = <function 8>,
fsize = <function 9>,
ftime = <function 10>,
getcwd = <function 11>,
getenv = <function 12>,
glob = <function 13>,
makedirs = <function 14>,
mkdir = <function 15>,
platform = <function 16>,
realpath = <function 17>,
remove = <function 18>,
removedirs = <function 19>,
rename = <function 20>,
rmdir = <function 21>,
setenv = <function 22>,
tmpdir = <function 23>,
touch = <function 24>,
type = <function 25>,
unlock = <function 26>,
walk = <function 27>
}
So it looks like some functions are missing, which I can use instead on my Arch machine and some I only get on my Ubuntu machine.
Can this be fixed by myself, or is it OS depended?
Thanks
Sebastian
Hello and thank you for the lpath
library!
I have a question about usage of path.split()
function.
I was trying to find a function to get a path's dirname and it seems path.split()
does exactly that. The problem is that for the input "/a/b/
it results into "/a/b/", ""
while I'd expect it to be "/a", "b/"
so that I can pass "/a"
to path.split()
next.
My exact use case is to get a a list of parent paths out of some path:
/a/b/c
/a/b
/a
/
and it seems I need to manually strip the trailing "/" when using path.split()
to achieve that. Am I missing some other utility function or usage pattern? Or maybe path.split()
should so some path normalization (stripping the trailing /
)?
please add license into repository, is a good practice :3
Both this module and lua-path uses path
as module name meaning I cannot have both installed.
Would you consider renaming your module to lpath
?
Is this intended, or a misspelling of path.suffix
? Thanks
Hello,
on linux (probably for all unix) there is no valid absolute path that starts with '//'
When i call path with the following inputs I get the following outputs and some of them are questionable.
path("/bla//blub") -> "/bla/blub" -> The middle // got turned into a /, this is fine. This leads me to the assumption that all '//' will be substituted by '/'. Which is totally fine on linux
path("//bla/blub") -> "//bla/blub" -> "//" did not get subsituted? Why... theres no reason not to do this. My only guess would be that this is some side effect from windows code where paths to network drives can start with double '\'
The issue also goes away when the path starts with 3 or more slashes. It only exists when using precisely two slashes.
Here is a small table of tests I did to determine the behavior of path(...)
See https://i.imgur.com/37gjcwh.png
Perhaps I am only missunderstanding the intended behavior.
Greetings
Alexander Schütz
Today I tested tmpdir on XP
E:\lpath>lua
Lua 5.3.4 Copyright (C) 1994-2017 Lua.org, PUC-Rio
> fs=require "path.fs"
> fs.tmpdir()
> fs.tmpdir()
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\lua_930310
>
Surprisingly, the first tmpdir failed but the second worked good.
I steped into and found s = lua_tostring(L, -1);
, here s is NULL.
Another inappropriate thing, srand((int)(ptrdiff_t)&L);
.Random seed is L
, which remains unchanged during the whole state.When I call tmpdir
for the first,second and third time,it will try to create directories which is already created before.Unless I clean,it will run slower and slower.
The library crashes when calling path.fs.glob('test.txt')
, where the file test.txt
exists
I just tried out your package and noticed a lot of the functions mentioned in the README are missing.
$ luarocks install --local lpath
Installing https://luarocks.org/lpath-0.1.0-1.rockspec
Cloning into 'lpath'...
remote: Counting objects: 11, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 11 (delta 0), reused 6 (delta 0), pack-reused 0
Receiving objects: 100% (11/11), 43.00 KiB | 0 bytes/s, done.
Checking connectivity... done.
gcc -O2 -fPIC -I/usr/local/include -c lpath.c -o lpath.o
gcc -shared -o path.so -L/usr/local/lib lpath.o
lpath 0.1.0-1 is now installed in /home/X/.luarocks (license: MIT/X11)
$ lua
Lua 5.3.4 Copyright (C) 1994-2017 Lua.org, PUC-Rio
> path = require 'path'
> require 'inspect'(path)
{
abs = <function 1>,
ansi = <function 2>,
isabs = <function 3>,
itercomp = <function 4>,
join = <function 5>,
rel = <function 6>,
split = <function 7>,
splitdrive = <function 8>,
splitext = <function 9>,
utf8 = <function 10>,
<metatable> = {
__call = <function 11>
}
}
Running luarocks make
on the repository yields the same result.
I'm running Luarocks 2.4.4 with Lua 5.3.4 on a Devuan Jessie machine.
When calling env.expand with invalid values lpath segfaults.
Example output from Terminal:
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
x = require("path.env")
x.expand("$(ls/)")
[1] 3195 segmentation fault lua
This was tested on Ubuntu 18.04 LTS
After looking through the code I think the issue is found in the following code:
wordexp_t p;
int ret, top = lua_gettop(L);
lua_pushcfunction(L, lp_exapndvars);
lua_pushlightuserdata(L, &p);
lua_pushlightuserdata(L, S);
ret = lua_pcall(L, 2, LUA_MULTRET, 0);
wordfree(&p);
if (ret != LUA_OK) return lua_pushnil(L), lua_insert(L, -2), 2;
return lua_gettop(L) - top;
when lp_exapndvars (which calls wordexp) errors it does not initialize or touch the variable p (passed via pointer) at all.
Meaning the struct p contains garbage data from the stack. wordfree will see this garbage data and think its pointers and try to reference/free those pointers. This is probably what causes the segfault.
Perhaps a call to memset(&p, 0,sizeof(wordexp_t)) before calling lp_exapndvars would fix this?
Alternatively you could evaluate the result value of wordexp and only call wordfree if wordexp returned 0.
I am looking to use lpath in my own project. Upon testing, I found that the wildcards didn't work as I would expect them to. If I do fs.glob "./*"
, it lists all subnodes recursively. However, if I do fs.glob "./*.lua"
, it will not match all .lua
files recursively, only at the top level. Using a double star (./**.lua
) changes nothing.
There is no documented behavior for this function. Would it be possible to have a section explaining how it works? And how would I be able to match all subnodes recursively with a certain extension using a glob iterator?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.