Comments (3)
Hi, in higher version, I think lfs.symlinkattributes(filepath).target
is the real path? - subject path if filepath
is symbolic path.
from luafilesystem.
@robertlzj no, the target
value is the (absolute or relative path) of the symlink.
You can have a foo1
symlink pointing to bar
or a foo2
symlink pointing to /home/xyz/bar
in /home/xyz/
foo1 -> bar
foo2 -> /home/xyz/bar
The realpath is use to travel in all "directories" and get out of any symlink to get a real uniq storage path.
It is usefull in more complicated case like
d /storage/
d /storage/users/
d /storage/users/xyz
l /home -> /storage/users
- in this case the realpath of
/home/xyz
is/storage/users/xyz
- in this case the realpath of
/home/xyz/foo1
is/storage/users/xyz/bar
and not/home/xyz/bar
- in this case the realpath of
/home/xyz/foo2
is/storage/users/xyz/bar
and not/home/xyz/bar
If we want to implement the realpath job in lua, we need to
- get the full path (the
target
value if it is absolute, or the current path + the target value), /home/xyz/bar in the current sample - start at the first left directory, if it is a link, substitute the value of the first directory by the symlink target value BUT before we also need to get the real path of this value.
- do the same thing with the next item in the path
It is a little complex ... the system realpath
know how to do this job perfectly !
Regards,
from luafilesystem.
Hi, thinks for your introduce about about realpath - the final path without symbolic.
I think it's easy? to iterate each directory and expand if it is symlink then recurs iterate, at last make up the realpath.
If there is realpath
in system would be nice of cause.
And in windows, I had just compare lfs.link/lfs.symlinkattributes.target and ln.exe.
target
also make sense on hardlink, if it is in virtual volume (which is treated as symlink/junction directory?), it points to actual directory of virtual volume.
Other test on multi levels of symlink, substitute virtual volume, and multi symlink parts in path.
I had thought final source above is realptah.
local lfs=require'lfs'
local vb=[[G:\]]--virtual base (on virtual volume)
local ab=[[E:\VirtualVolume\]]--actual base
if not lfs.attributes(vb) then
assert(lfs.attributes(ab))
os.execute('subst '..vb..' '..ab)
end
lfs.chdir(vb)
assert(not lfs.attributes'D' and not lfs.attributes'S')
os.execute('mkdir D')--origin
assert(lfs.link('D','S',true))--symlink directory
--
lfs.chdir(vb..[[S\]])
local E={close=function()end}
assert(not (io.open'O.txt' or E):close() and not (io.open'S.txt' or E):close() and not (io.open'S2.txt' or E):close() and not (io.open'S2b.txt' or E):close() and not (io.open'H.txt' or E):close() and not (io.open'Hb.txt' or E):close() and not (io.open'H2.txt' or E):close() and not (io.open'H2b.txt' or E):close())
----O: origin, H: config as hardlink, S: symlink
io.open('O.txt','w'):close()
lfs.link('O.txt','S.txt',true)
--hardlink
lfs.link('S.txt','H.txt')
os.execute('ln >nul 2>nul S.txt Hb.txt')
--symlink level 2
lfs.link('S.txt','S2.txt',true)
os.execute('ln >nul 2>nul --symbolic S.txt S2b.txt')
--hardlink level 2
lfs.link('S2.txt','H2.txt')
os.execute('ln >nul 2>nul S2.txt H2b.txt')
----
assert(lfs.symlinkattributes'H.txt'.mode=='link')
assert(lfs.symlinkattributes'Hb.txt'.mode=='link')
assert(lfs.symlinkattributes'S.txt'.mode=='link')
assert(lfs.symlinkattributes'S2.txt'.mode=='link')
assert(lfs.symlinkattributes'S2b.txt'.mode=='link')
assert(lfs.symlinkattributes'H2.txt'.mode=='link')
assert(lfs.symlinkattributes'H2b.txt'.mode=='link')
----
local function ln_target(fn)--show the target of a symbolic link
local r=io.popen('ln --symbolic '..fn)
return string.match(r:read'a','%-> (.+)\n')
end
assert(ln_target'H.txt'=='O.txt')
assert(ln_target'Hb.txt'=='O.txt')
assert(ln_target'S.txt'=='O.txt')
assert(ln_target'S2.txt'=='S.txt')
assert(ln_target'S2b.txt'=='S.txt')
assert(ln_target'H2.txt'=='S.txt')
assert(ln_target'H2b.txt'=='S.txt')
----
local t=(lfs.attributes(ab) and ab or vb)..[[D\O.txt]]
assert(lfs.symlinkattributes'H.txt'.target==t)
assert(lfs.symlinkattributes'Hb.txt'.target==t)
assert(lfs.symlinkattributes'S.txt'.target==t)
assert(lfs.symlinkattributes'S2.txt'.target==t)
assert(lfs.symlinkattributes'S2b.txt'.target==t)
assert(lfs.symlinkattributes'H2.txt'.target==t)
assert(lfs.symlinkattributes'H2b.txt'.target==t)
----
os.execute('del O.txt S.txt S2.txt S2b.txt H.txt Hb.txt H2.txt H2b.txt')
lfs.chdir(vb)
--
os.execute('rmdir D')
os.execute('rmdir S')
print'test done.'
from luafilesystem.
Related Issues (20)
- Fatal Error - /usr/include/features.h:461:12: fatal error: sys/cdefs.h: No such file or directory HOT 2
- lfs.chdir Changes current working directory to volume without end slash wont work
- lfs.link (symlink, new[, symlink]) always create a symbolic link
- Why is luarocks saying : Error: unknown option '-e' when installing luacheck? HOT 4
- load on windows fails HOT 2
- Upload new dev-rockspec to LuaRocks.org HOT 4
- Update homepage link on this GitHub project HOT 1
- performance in windows of lfs.attributes inside lfs.dir loop
- lfs.link unsupported on windows even in developper mode HOT 1
- keep got warning message with openresty
- Function lfs.mkdir() is not idempotent and hence not thread safe
- error when retrieve symlinkatrributes at directory symlink HOT 1
- Copying/moving files HOT 5
- Documentation site 404 error? HOT 1
- Update homepage HOT 5
- error while installing HOT 3
- missing prototypes warnings when building on windows using msys2
- Error when installing on windows via luarocks HOT 3
- Does not compile in Windows in Unicode (WCHAR) mode
- pl.Path.isdir doesn't work properly if the path prefix start by "~" HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from luafilesystem.