Beispiel #1
0
    def Run(self, args):
        self.follow_links = args.follow_links
        self.process_non_regular_files = args.process_non_regular_files

        self.stat_cache = utils.StatCache()

        # Generate a list of mount points where we stop recursive searches.
        if args.xdev == args.XDev.NEVER:
            # Never cross device boundaries, stop at all mount points.
            self.mountpoints_blacklist = set(
                [p.mountpoint for p in psutil.disk_partitions(all=True)])
        elif args.xdev == args.XDev.LOCAL:
            # Descend into file systems on physical devices only.
            self.mountpoints_blacklist = (
                set([p.mountpoint for p in psutil.disk_partitions(all=True)]) -
                set([p.mountpoint for p in psutil.disk_partitions(all=False)]))
        elif args.xdev == args.XDev.ALWAYS:
            # Never stop at any device boundary.
            self.mountpoints_blacklist = set()

        for fname in self.CollectGlobs(args.paths):
            self.Progress()
            try:
                matches = self._Validate(args, fname)
                result = self._ProcessFile(args, fname)
                result.matches = matches
                self.SendReply(result)
            except _SkipFileException:
                pass
Beispiel #2
0
    def Run(self, args):
        self.stat_cache = utils.StatCache()

        action = self._ParseAction(args)
        for path in self._GetExpandedPaths(args):
            self.Progress()
            try:
                matches = self._Validate(args, path)
                result = rdf_file_finder.FileFinderResult()
                result.matches = matches
                action.Execute(path, result)
                self.SendReply(result)
            except _SkipFileException:
                pass
Beispiel #3
0
  def testSmartSymlinkCache(self):
    with open(self.Path("foo"), "w") as fd:
      fd.write("12345")

    stat_cache = utils.StatCache()

    with mock.patch.object(utils, "Stat", wraps=utils.Stat) as stat_mock:
      foo_stat = stat_cache.Get(self.Path("foo"), follow_symlink=False)
      self.assertEqual(foo_stat.GetSize(), 5)
      self.assertTrue(stat_mock.called)

    with mock.patch.object(utils, "Stat", wraps=utils.Stat) as stat_mock:
      other_foo_stat = stat_cache.Get(self.Path("foo"), follow_symlink=True)
      self.assertEqual(other_foo_stat.GetSize(), 5)
      self.assertFalse(stat_mock.called)
Beispiel #4
0
  def testFollowSymlink(self):
    with open(self.Path("foo"), "w") as fd:
      fd.write("123456")
    os.symlink(self.Path("foo"), self.Path("bar"))

    stat_cache = utils.StatCache()

    with mock.patch.object(utils, "Stat", wraps=utils.Stat) as stat_mock:
      bar_stat = stat_cache.Get(self.Path("bar"), follow_symlink=False)
      self.assertTrue(bar_stat.IsSymlink())
      self.assertTrue(stat_mock.called)

    with mock.patch.object(utils, "Stat", wraps=utils.Stat) as stat_mock:
      foo_stat = stat_cache.Get(self.Path("bar"), follow_symlink=True)
      self.assertFalse(foo_stat.IsSymlink())
      self.assertEqual(foo_stat.GetSize(), 6)
      self.assertTrue(stat_mock.called)
Beispiel #5
0
  def testBasicUsage(self):
    with open(self.Path("foo"), "w") as fd:
      fd.write("123")
    with open(self.Path("bar"), "w") as fd:
      fd.write("123456")
    with open(self.Path("baz"), "w") as fd:
      fd.write("123456789")

    stat_cache = utils.StatCache()

    with mock.patch.object(utils, "Stat", wraps=utils.Stat) as stat_mock:
      foo_stat = stat_cache.Get(self.Path("foo"))
      self.assertEqual(foo_stat.GetSize(), 3)
      self.assertTrue(stat_mock.called)

    with mock.patch.object(utils, "Stat", wraps=utils.Stat) as stat_mock:
      bar_stat = stat_cache.Get(self.Path("bar"))
      self.assertEqual(bar_stat.GetSize(), 6)
      self.assertTrue(stat_mock.called)

    with mock.patch.object(utils, "Stat", wraps=utils.Stat) as stat_mock:
      other_foo_stat = stat_cache.Get(self.Path("foo"))
      self.assertEqual(other_foo_stat.GetSize(), 3)
      self.assertFalse(stat_mock.called)

    with mock.patch.object(utils, "Stat", wraps=utils.Stat) as stat_mock:
      other_bar_stat = stat_cache.Get(self.Path("bar"))
      self.assertEqual(other_bar_stat.GetSize(), 6)
      self.assertFalse(stat_mock.called)

    with mock.patch.object(utils, "Stat", wraps=utils.Stat) as stat_mock:
      baz_stat = stat_cache.Get(self.Path("baz"))
      self.assertEqual(baz_stat.GetSize(), 9)
      self.assertTrue(stat_mock.called)

    with mock.patch.object(utils, "Stat", wraps=utils.Stat) as stat_mock:
      other_baz_stat = stat_cache.Get(self.Path("baz"))
      self.assertEqual(other_baz_stat.GetSize(), 9)
      self.assertFalse(stat_mock.called)