def test_mirror_one_file_one_dir(self): m1 = open_fs('mem://') m1.settext('foo', 'hello') m1.makedir('bar') m2 = open_fs('mem://') mirror(m1, m2) self.assert_compare_fs(m1, m2)
def mount_fs(self, dst_path: str, fs_url: str = None, owner_uid: Optional[int] = 0, group_gid: Optional[int] = 0, perms: Optional[Union[Permissions, int]] = 0o755) -> subfs.SubFS: """ To be called to mount individual filesystems. :param fs_url: Location/URL for the file system that is to be mounted. :param dst_path: Place in the Conpot's file system where the files would be placed. This should be relative to FS root. :param owner_uid: The owner `user` **UID** of the directory and the sub directory. Default is root/ :param group_gid: The group 'group` to which the directory beings. Defaults to root. :param perms: Permission UMASK """ path = self.norm_path(dst_path) if self.exists(path) and self.isdir(path): if not fs_url: new_dir = self.create_jail(path) else: temp_fs = open_fs(fs_url=fs_url) with temp_fs.lock(): new_dir = self.opendir(self.norm_path(dst_path), factory=SubAbstractFS) mirror.mirror(src_fs=temp_fs, dst_fs=new_dir) self._cache.update({path: info for path, info in self.walk.info(namespaces=['basic', 'access', 'details', 'stat'])}) del temp_fs # delete the instance since no longer required new_dir.default_uid, new_dir.default_gid = owner_uid, group_gid new_dir.chown('/', uid=owner_uid, gid=group_gid, recursive=True) new_dir.chmod('/', mode=perms, recursive=True) return new_dir else: raise fs.errors.DirectoryExpected('{} path does not exist'.format(path))
def test_mirror_one_file_one_dir(self): m1 = open_fs("mem://") m1.settext("foo", "hello") m1.makedir("bar") m2 = open_fs("mem://") mirror(m1, m2, workers=self.WORKERS) self.assert_compare_fs(m1, m2)
def test_mirror_one_file_one_dir(self): m1 = open_fs("mem://") m1.writetext("foo", "hello") m1.makedir("bar") m2 = open_fs("mem://") mirror(m1, m2, workers=self.WORKERS, preserve_time=True) self.assert_compare_fs(m1, m2)
def _initialize_fs(self, src_path: str) -> None: """ Copies all data into Conpot's created fs folder and builds up the cache. :param src_path: FS URLS """ # copy all contents from the source path the filesystem. src_fs = open_fs(src_path) logger.debug( "Building up file system: copying contents from the source path {}" .format(src_path)) with src_fs.lock(): mirror.mirror(src_fs=src_fs, dst_fs=self.vfs) self._cache.update({ path: info for path, info in self.walk.info( namespaces=["basic", "access", "details", "stat"]) }) self._cache["/"] = self._wrap_fs.getinfo( "/", namespaces=["basic", "access", "details", "stat", "link"]) self.chown("/", self.default_uid, self.default_gid, recursive=True) self.chmod("/", self.default_perms, recursive=True) self.built_cache = ( True # FS has been built. Now all info must be accessed from cache. ) src_fs.close() del src_fs
def test_mirror_extra_dir(self): m1 = open_fs("mem://") m1.writetext("foo", "hello") m1.makedir("bar") m2 = open_fs("mem://") m2.makedir("baz") mirror(m1, m2, workers=self.WORKERS) self.assert_compare_fs(m1, m2)
def test_mirror_wrong_type(self): m1 = open_fs('mem://') m1.settext('foo', 'hello') m1.makedir('bar') m2 = open_fs('mem://') m2.makedir('foo') m2.touch('bar') mirror(m1, m2) self.assert_compare_fs(m1, m2)
def test_mirror_wrong_type(self): m1 = open_fs("mem://") m1.settext("foo", "hello") m1.makedir("bar") m2 = open_fs("mem://") m2.makedir("foo") m2.touch("bar") mirror(m1, m2, workers=self.WORKERS) self.assert_compare_fs(m1, m2)
def test_mirror_update(self): m1 = open_fs('mem://') m1.settext('foo', 'hello') m1.makedir('bar') m2 = open_fs('mem://') mirror(m1, m2) self.assert_compare_fs(m1, m2) m2.appendtext('foo', ' world!') mirror(m1, m2) self.assert_compare_fs(m1, m2)
def test_mirror_update(self): m1 = open_fs("mem://") m1.settext("foo", "hello") m1.makedir("bar") m2 = open_fs("mem://") mirror(m1, m2, workers=self.WORKERS) self.assert_compare_fs(m1, m2) m2.appendtext("foo", " world!") mirror(m1, m2, workers=self.WORKERS) self.assert_compare_fs(m1, m2)
def _initialize_fs(self, src_path: str) -> None: """ Copies all data into Conpot's created fs folder and builds up the cache. :param src_path: FS URLS """ # copy all contents from the source path the filesystem. src_fs = open_fs(src_path) logger.debug('Building up file system: copying contents from the source path {}'.format(src_path)) with src_fs.lock(): mirror.mirror(src_fs=src_fs, dst_fs=self.vfs) self._cache.update({path: info for path, info in self.walk.info(namespaces=['basic', 'access', 'details', 'stat'])}) self._cache['/'] = self._wrap_fs.getinfo('/', namespaces=['basic', 'access', 'details', 'stat', 'link']) self.chown('/', self.default_uid, self.default_gid, recursive=True) self.chmod('/', self.default_perms, recursive=True) self.built_cache = True # FS has been built. Now all info must be accessed from cache. src_fs.close() del src_fs
def mount_fs( self, dst_path: str, fs_url: str = None, owner_uid: Optional[int] = 0, group_gid: Optional[int] = 0, perms: Optional[Union[Permissions, int]] = 0o755, ) -> subfs.SubFS: """ To be called to mount individual filesystems. :param fs_url: Location/URL for the file system that is to be mounted. :param dst_path: Place in the Conpot's file system where the files would be placed. This should be relative to FS root. :param owner_uid: The owner `user` **UID** of the directory and the sub directory. Default is root/ :param group_gid: The group 'group` to which the directory beings. Defaults to root. :param perms: Permission UMASK """ path = self.norm_path(dst_path) if self.exists(path) and self.isdir(path): if not fs_url: new_dir = self.create_jail(path) else: temp_fs = open_fs(fs_url=fs_url) with temp_fs.lock(): new_dir = self.opendir( self.norm_path(dst_path), factory=SubAbstractFS ) mirror.mirror(src_fs=temp_fs, dst_fs=new_dir) self._cache.update( { path: info for path, info in self.walk.info( namespaces=["basic", "access", "details", "stat"] ) } ) del temp_fs # delete the instance since no longer required new_dir.default_uid, new_dir.default_gid = owner_uid, group_gid new_dir.chown("/", uid=owner_uid, gid=group_gid, recursive=True) new_dir.chmod("/", mode=perms, recursive=True) return new_dir else: raise fs.errors.DirectoryExpected("{} path does not exist".format(path))
def test_mirror_delete_replace(self): m1 = open_fs("mem://") m1.settext("foo", "hello") m1.makedir("bar") m2 = open_fs("mem://") mirror(m1, m2, workers=self.WORKERS) self.assert_compare_fs(m1, m2) m2.remove("foo") mirror(m1, m2, workers=self.WORKERS) self.assert_compare_fs(m1, m2) m2.removedir("bar") mirror(m1, m2, workers=self.WORKERS) self.assert_compare_fs(m1, m2)
def test_mirror_delete_replace(self): m1 = open_fs('mem://') m1.settext('foo', 'hello') m1.makedir('bar') m2 = open_fs('mem://') mirror(m1, m2) self.assert_compare_fs(m1, m2) m2.remove('foo') mirror(m1, m2) self.assert_compare_fs(m1, m2) m2.removedir('bar') mirror(m1, m2) self.assert_compare_fs(m1, m2)
def test_empty_mirror(self): m1 = open_fs('mem://') m2 = open_fs('mem://') mirror(m1, m2) self.assert_compare_fs(m1, m2)
def test_empty_mirror(self): m1 = open_fs("mem://") m2 = open_fs("mem://") mirror(m1, m2, workers=self.WORKERS) self.assert_compare_fs(m1, m2)
def test_mirror_one_file(self): m1 = open_fs("mem://") m1.writetext("foo", "hello") m2 = open_fs("mem://") mirror(m1, m2, workers=self.WORKERS) self.assert_compare_fs(m1, m2)