def _ExecuteHash(self, fname, args): stat_opts = rdf_file_finder.FileFinderStatActionOptions( resolve_links=True, collect_ext_attrs=args.action.hash.collect_ext_attrs) stat_entry = self.Stat(fname, stat_opts) hash_entry = self.Hash(fname, args.action.hash) return rdf_file_finder.FileFinderResult(stat_entry=stat_entry, hash_entry=hash_entry)
def _ExecuteDownload(self, fname, args): stat_opts = rdf_file_finder.FileFinderStatActionOptions( resolve_links=True, collect_ext_attrs=args.action.download.collect_ext_attrs) stat_entry = self.Stat(fname, stat_opts) uploaded_file = self.Upload(fname, args.action.download) if uploaded_file: uploaded_file.stat_entry = stat_entry return rdf_file_finder.FileFinderResult(stat_entry=stat_entry, uploaded_file=uploaded_file)
def testLinkStat(self): """Tests resolving symlinks when getting stat entries.""" test_dir = os.path.join(self.temp_dir, "lnk_stat_test") lnk = os.path.join(test_dir, "lnk") lnk_target = os.path.join(test_dir, "lnk_target") os.mkdir(test_dir) with open(lnk_target, "wb") as fd: fd.write("sometext") os.symlink(lnk_target, lnk) paths = [lnk] link_size = os.lstat(lnk).st_size target_size = os.stat(lnk).st_size for expected_size, resolve_links in [(link_size, False), (target_size, True)]: stat_action = rdf_file_finder.FileFinderAction( action_type=rdf_file_finder.FileFinderAction.Action.STAT, stat=rdf_file_finder.FileFinderStatActionOptions( resolve_links=resolve_links)) results = self._RunFileFinder(paths, stat_action) self.assertEqual(len(results), 1) res = results[0] self.assertEqual(res.stat_entry.st_size, expected_size)
def _StatAction(**kwargs): action_type = rdf_file_finder.FileFinderAction.Action.STAT opts = rdf_file_finder.FileFinderStatActionOptions(**kwargs) return rdf_file_finder.FileFinderAction(action_type=action_type, stat=opts)