我使用以下指挥方法收集目录:
os.chroot("/mydir")
How to return to directory to previous - before chrooting? Maybe it is possible to unchroot directory?
感谢Phihag。 我找到了解决办法。 简单例子:
import os
os.mkdir( /tmp/new_dir )
dir1 = os.open( . , os.O_RDONLY)
dir2 = os.open( /tmp/new_dir , os.O_RDONLY)
os.getcwd() # we are in tmp
os.chroot( /tmp/new_dir ) # chrooting new_dir directory
os.fchdir(dir2)
os.getcwd() # we are in chrooted directory, but path is / . It s OK.
os.fchdir(dir1)
os.getcwd() # we came back to not chrooted tmp directory
os.close(dir1)
os.close(dir2)