--- /dev/null
+#!/usr/bin/python -u
+# vim:fileencoding=utf-8:et:ts=4:sw=4:sts=4
+#
+# Copyright (C) 2013 Intel Corporation <markus.lehtonen@linux.intel.com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+"""The check subcommand"""
+
+import logging
+import os
+
+from repocache_adm.common import AdmError, SubcommandBase, repo_is_bare
+
+class Check(SubcommandBase):
+ """Subcommand for checking the repo cache"""
+
+ name = 'check'
+ description = 'Check consistency of repocache'
+ help_msg = None
+
+ @classmethod
+ def main(cls, args):
+ """Entry point for 'check' subcommand"""
+
+ log = get_logger(cls.name)
+
+ if not os.path.isdir(args.cache_dir):
+ log.error("repocache basedir '%s' not found" % args.cache_dir)
+ return 1
+
+ log.info("Checking repository cache in '%s'" % args.cache_dir)
+
+ basedirs = []
+ basefiles = []
+ for fname in os.listdir(args.cache_dir):
+ if os.path.isdir(os.path.join(args.cache_dir, fname)):
+ basedirs.append(fname)
+ else:
+ basefiles.append(fname)
+ if basefiles:
+ log.warning("Non-directory files found in repocache base:\n%s" %
+ '\n'.join([' ' + fname for fname in basefiles]))
+
+ for dname in basedirs:
+ for fname in os.listdir(os.path.join(args.cache_dir, dname)):
+ rel_path = os.path.join(dname, fname)
+ full_path = os.path.join(args.cache_dir, rel_path)
+ if os.path.isdir(full_path):
+ try:
+ repo_is_bare(full_path)
+ except AdmError:
+ log.warning("Cache contains directory %s that doesn't "
+ "look like a Git repository" % rel_path)
+ else:
+ if not os.path.isfile(full_path + '.lock'):
+ log.warning("Repo '%s' doesn't have a lock file" %
+ rel_path)
+ else:
+ stat = os.stat(full_path)
+ basename, ext = os.path.splitext(full_path)
+ if ext != '.lock':
+ log.warning("Cache contains regular file that doesn't "
+ "look like a lock file: %s" % rel_path)
+ else:
+ if not os.path.isdir(basename):
+ log.warning("Orphan lock file '%s'" % rel_path)
+ if stat.st_size != 0:
+ log.warning("Non-empty lock file: %s (%d bytes)" %
+ (rel_path, stat.st_size))
+ return 0
+