在我的Linux(CentOS 6)系统上,我安装了一个sshfs网络共享/data/remote
。我可以通过bash
ln -s /data/remote/source /data/remote/destination
但是以下python代码失败
# test_os_link.py
import os
if not os.path.exists('/data/remote/destination'):
os.link('/data/remote/source', '/data/remote/destination')
失败
Traceback (most recent call last):
File "test_os_link.py", line 2, in <module>
os.link('/data/remote/source', '/data/remote/destination')
OSError: [Errno 38] Function not implemented
sshfs挂载为
sshfs -o follow_symlinks user@host:/data/remote /data/remote
如您所见,远程和本地系统上的目录结构相同,因此/data/remote
中的符号链接在两个系统上都有效。
strace报告以下内容:
stat("test_os_link.py", {st_mode=S_IFREG|0644, st_size=167, ...}) = 0
open("test_os_link.py", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=167, ...}) = 0
ioctl(3, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7fff7240bf10) = -1 ENOTTY (Inappropriate ioctl for device)
fstat(3, {st_mode=S_IFREG|0644, st_size=167, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f48c6080000
lseek(3, 0, SEEK_CUR) = 0
read(3, "import os\nos.link(\"/data/remote/dest"..., 4096) = 167
lseek(3, 167, SEEK_SET) = 167
brk(0x1e64000) = 0x1e64000
read(3, "", 4096) = 0
close(3) = 0
munmap(0x7f48c6080000, 4096) = 0
mmap(NULL, 200704, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f48c6050000
mmap(NULL, 266240, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f48c600f000
brk(0x1e85000) = 0x1e85000
mmap(NULL, 266240, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f48c5fce000
link("/data/remote/source", "/data/remote/destination") = -1 ENOSYS (Function not implemented)
write(2, "Traceback (most recent call last"..., 35Traceback (most recent call last):
) = 35
write(2, " File \"test_os_link.py\", line 2"..., 46 File "test_os_link.py", line 2, in <module>
) = 46
open("test_os_link.py", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=167, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f48c5fcd000
read(3, "import os\nos.link(\"/data/remote/dest"..., 4096) = 167
write(2, " ", 4 ) = 4
write(2, "os.link(\"/data/remote/source"..., 79os.link("/data/remote/source","/data/remote/destination")
) = 79
close(3) = 0
munmap(0x7f48c5fcd000, 4096) = 0
write(2, "OSError", 7OSError) = 7
write(2, ": ", 2: ) = 2