运维 - 如何实现linux与windows软链接底层兼容?
巴扎黑
巴扎黑 2017-04-17 16:18:45
0
3
401

即,将一个linux软链接拷贝到win环境下,在文件不被做任何修改的情况下,win依然能够使用比链接,请问如何实现?

这个问题很高端,也很棘手,有什么想法一起讨论讨论。

巴扎黑
巴扎黑

reply all(3)
小葫芦

I just recently saw that Git for Windows has added soft link support. You can think of git clone as a complex file copy.

Under linux:

mkdir symbolic-link-test
cd symbolic-link-test
git init
touch readme.md
ln -s readme.md link-to-readme.md
git add .
git commit -m "init"

Then submit it to github, and then git clone it with administrator rights under windows:

git clone -c core.symlinks=true git@xxxxx/symbolic-link-test.git

Result:

Writing content to link-to-readme.md will appear in readme.md (using powershell):

Mode contains l:

So it is possible to copy soft links, the general process is:

  1. Record the information of the soft link under Linux when copying, for example, this is a soft link and points to that file

  2. When pasting to windows, use the Windows Symbolic link to reconstruct the file based on the saved soft link information

A little addition: If you only copy the soft link and not the file it points to, or the soft link is an absolute path, this method will not work.

迷茫

It is impossible to be compatible.
You can try to use ext2fsd to mount the ext partition in Windows, copy the soft link file inside and use hex editor to view the content, and analyze the file structure to parse it.
Or try msys Can readlink be read in +mingw,
or can the win10 preview version be installed with the linux subsystem (ubuntu), give it a try?

迷茫

What you should consider is to first mount the Linux partition under Windows, and then try to use shortcuts or mklink to create a pointing connection from the Linux partition, instead of considering whether copying the soft connection that has been created under Linux can be compatible under Windows .
Theoretically, soft links overcome the compatibility issues of hard links on different file systems. We can create soft links on different file partitions or even network file systems. However, considering the differences in the operating systems of Windows and Linux, you Soft links created under Linux are not necessarily guaranteed to be correctly recognized and referenced under Windows. So, don’t think about copying. If you really need it, try mounting the partition directly, and then use mklink to create a soft connection from the Linux partition to Windows!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!