From 3bbb45d84814d4bf432ec7f6872fa94ea2ec741b Mon Sep 17 00:00:00 2001 From: Aleš Raszka Date: Jan 18 2016 10:09:45 +0000 Subject: Don't upload small text files to lookaside cache If it's necessary to upload small text files, it's able to enforce it with --force flag Patch: Tomas Mraz Resolves: bz767264 Signed-off-by: Aleš Raszka --- diff --git a/src/pyrpkg/cli.py b/src/pyrpkg/cli.py index 8ecb30c..e1f48dd 100755 --- a/src/pyrpkg/cli.py +++ b/src/pyrpkg/cli.py @@ -22,8 +22,10 @@ import string import xmlrpclib import pwd import koji +import subprocess OSBS_DEFAULT_CONF_FILE = "/etc/osbs/osbs.conf" +LOOKASIDE_MAX_FILE_SIZE = 100000 class cliClient(object): """This is a client class for rpkg clients.""" @@ -613,6 +615,11 @@ defined, packages will be built sequentially.""" % {'name': self.name}) 'cache and remove any existing ones. The "sources" ' 'and .gitignore files will be updated with the new ' 'uploaded file(s).') + self.new_sources_parser.add_argument('--force', + default=False, + action='store_true', + help='Force the upload of small ' + 'textual files') self.new_sources_parser.add_argument('files', nargs='+') self.new_sources_parser.set_defaults( command=self.new_sources, replace=True) @@ -1133,6 +1140,13 @@ defined, packages will be built sequentially.""" % {'name': self.name}) if not os.path.isfile(file): raise Exception('Path does not exist or is ' 'not a file: %s' % file) + if not self.args.force \ + and os.stat(file).st_size < LOOKASIDE_MAX_FILE_SIZE \ + and 'text' in subprocess.check_output(['file', file]): + raise Exception('The file %s is small and textual, ' + 'it should be added ' + 'to the git tree directly' % file) + self.cmd.upload(self.args.files, replace=self.args.replace) self.log.info("Source upload succeeded. Don't forget to commit the " "sources file")