def test_get_update_links_wspace(self): wspath = os.path.join(self.tmp_dir, 'wspace') hfspath = os.path.join(self.tmp_dir, 'objectsfs') ohfs = MultihashFS(hfspath) key = ohfs.put(HDATA_IMG_1) fidx = FullIndex(self.tmp_dir, self.tmp_dir) cachepath = os.path.join(self.tmp_dir, 'cachefs') cache = Cache(cachepath, '', '') testbucketname = os.getenv('MLGIT_TEST_BUCKET', 'ml-git-datasets') c = get_sample_config_spec(testbucketname, testprofile, testregion) r = LocalRepository(c, hfspath) r._update_cache(cache, key) mfiles = {} files = {DATA_IMG_1} r._update_links_wspace(cache, fidx, files, key, wspath, mfiles, Status.u.name, 'strict') wspace_file = os.path.join(wspath, DATA_IMG_1) set_write_read(wspace_file) self.assertTrue(os.path.exists(wspace_file)) self.assertEqual(self.md5sum(HDATA_IMG_1), self.md5sum(wspace_file)) st = os.stat(wspace_file) fi = fidx.get_index() for k, v in fi.items(): self.assertEqual(k, os.path.join('data', 'imghires.jpg')) self.assertEqual(v['hash'], 'zdj7WjdojNAZN53Wf29rPssZamfbC6MVerzcGwd9tNciMpsQh') self.assertEqual(v['status'], 'u') self.assertEqual(v['ctime'], st.st_ctime) self.assertEqual(v['mtime'], st.st_mtime) self.assertTrue(st.st_nlink == 2) self.assertEqual(mfiles, {DATA_IMG_1: 'zdj7WjdojNAZN53Wf29rPssZamfbC6MVerzcGwd9tNciMpsQh'})
def ilink(self, key, dstfile): srckey = self._get_hashpath(key) ensure_path_exists(os.path.dirname(dstfile)) log.debug(output_messages['DEBUG_LINK_FROM_TO'] % (srckey, dstfile), class_name=HASH_FS_CLASS_NAME) if os.path.exists(dstfile) is True: set_write_read(dstfile) os.unlink(dstfile) os.link(srckey, dstfile)
def ilink(self, key, dstfile): srckey = self._get_hashpath(key) ensure_path_exists(os.path.dirname(dstfile)) log.debug('Link from [%s] to [%s]' % (srckey, dstfile), class_name=HASH_FS_CLASS_NAME) if os.path.exists(dstfile) is True: set_write_read(dstfile) os.unlink(dstfile) os.link(srckey, dstfile)
def link(self, key, srcfile, force=True): dstkey = self._get_hashpath(key) ensure_path_exists(os.path.dirname(dstkey)) log.debug(output_messages['DEBUG_LINK_FROM_TO'] % (srcfile, key), class_name=HASH_FS_CLASS_NAME) if os.path.exists(dstkey) is True: if force is True: try: set_write_read(srcfile) os.unlink(srcfile) os.link(dstkey, srcfile) except FileNotFoundError as e: log.debug(str(e), class_name=HASH_FS_CLASS_NAME) raise e return os.link(srcfile, dstkey)
def test_update(self): mlgit_dir = os.path.join(self.tmp_dir, '.ml-git') objectpath = os.path.join(mlgit_dir, 'objects-test') manifest = os.path.join(self.tmp_dir, 'manifest.yaml') yaml_save( { 'zdj7WgHSKJkoJST5GWGgS53ARqV7oqMGYVvWzEWku3MBfnQ9u': {'think-hires.jpg'} }, manifest) data = os.path.join(self.test_dir, 'data') c = Cache(objectpath, data, manifest) c.update() set_write_read(os.path.join(self.test_dir, data, 'think-hires.jpg')) st = os.stat(os.path.join(self.test_dir, data, 'think-hires.jpg')) self.assertTrue(st.st_nlink > 1) self.assertTrue( c.exists('zdj7WgHSKJkoJST5GWGgS53ARqV7oqMGYVvWzEWku3MBfnQ9u'))