1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-01-12 16:56:15 +01:00

- support limit_size parameter during update

also added testcases
This commit is contained in:
Marcus Huewe 2010-08-23 11:29:57 +02:00
parent b6a2266a5e
commit e91475508e
18 changed files with 112 additions and 10 deletions

View File

@ -228,11 +228,12 @@ def os_path_samefile(path1, path2):
class File:
"""represent a file, including its metadata"""
def __init__(self, name, md5, size, mtime):
def __init__(self, name, md5, size, mtime, skipped=False):
self.name = name
self.md5 = md5
self.size = size
self.mtime = mtime
self.skipped = skipped
def __repr__(self):
return self.name
def __str__(self):
@ -1135,6 +1136,7 @@ class Package:
int(node.get('mtime')))
if node.get('skipped'):
self.skipped.append(f.name)
f.skipped = True
except:
# okay, a very old version of _files, which didn't contain any metadata yet...
f = File(node.get('name'), '', 0, 0)
@ -1448,8 +1450,9 @@ rev: %s
f = []
fmeta = ET.fromstring(filesmeta)
for i in fmeta.findall('entry'):
skipped = i.get('skipped') is not None
f.append(File(i.get('name'), i.get('md5'),
int(i.get('size')), int(i.get('mtime'))))
int(i.get('size')), int(i.get('mtime')), skipped))
return f
def __get_rev_changes(self, revfiles):
@ -1459,7 +1462,14 @@ rev: %s
revfilenames = []
for f in revfiles:
revfilenames.append(f.name)
if f.name in self.filenamelist:
# treat skipped like deleted files
if f.skipped:
deleted.append(f)
continue
# treat skipped like added files
# problem: this overwrites existing files during the update
# (because skipped files aren't in self.filenamelist_unvers)
if f.name in self.filenamelist and not f.name in self.skipped:
kept.append(f)
else:
added.append(f)
@ -1522,20 +1532,20 @@ rev: %s
# this can't happen
elif f in deleted:
deleted.remove(f)
self.__update(kept, added, deleted, fm, root.get('rev'), service_files, limit_size)
self.__update(kept, added, deleted, fm, root.get('rev'), service_files)
os.unlink(os.path.join(self.storedir, '_in_update', '_files'))
os.rmdir(os.path.join(self.storedir, '_in_update'))
# ok everything is ok (hopefully)...
fm = show_files_meta(self.apiurl, self.prjname, self.name, revision=rev)
fm = show_files_meta(self.apiurl, self.prjname, self.name, revision=rev, limit_size=limit_size)
rfiles = self.__get_files(fm)
store_write_string(self.absdir, '_files', fm, subdir='_in_update')
kept, added, deleted = self.__get_rev_changes(rfiles)
self.__update(kept, added, deleted, fm, rev, service_files, limit_size)
self.__update(kept, added, deleted, fm, rev, service_files)
os.unlink(os.path.join(self.storedir, '_in_update', '_files'))
if os.path.isdir(os.path.join(self.storedir, '_in_update')):
os.rmdir(os.path.join(self.storedir, '_in_update'))
def __update(self, kept, added, deleted, fm, rev = None, service_files = False, limit_size = None):
def __update(self, kept, added, deleted, fm, rev = None, service_files = False):
pathn = getTransActPath(self.dir)
# check for conflicts with existing files
for f in added:
@ -5132,8 +5142,8 @@ def getStatus(pacs, prj_obj=None, verbose=False, quiet=False, excluded=False):
continue
if filename in p.excluded and not excluded:
continue
if filename in p.skipped:
continue
# if filename in p.skipped:
# continue
s = p.status(filename)
if s == 'F':
lines.append(statfrmt('!', pathjoin(p.dir, filename)))

View File

@ -200,6 +200,49 @@ class TestUpdate(unittest.TestCase):
self.assertEqual(sys.stdout.getvalue(), exp)
self.__check_digests('testUpdateRestore_files')
@GET('http://localhost/source/osctest/limitsize?rev=latest', file='testUpdateLimitSizeNoChange_filesremote')
@GET('http://localhost/source/osctest/limitsize/_meta', file='meta.xml')
def testUpdateLimitSizeNoChange(self):
"""
a new file was added to the remote package but isn't checked out because
of the size constraint
"""
self.__change_to_pkg('limitsize')
osc.core.Package('.').update(limit_size=50)
self.assertTrue(len(EXPECTED_REQUESTS) == 0)
exp = 'D bigfile\nAt revision 2.\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self.assertFalse(os.path.exists(os.path.join('.osc', 'bigfile')))
self.assertFalse(os.path.exists('bigfile'))
self.__check_digests('testUpdateLimitSizeNoChange_files', 'bigfile')
@GET('http://localhost/source/osctest/limitsize?rev=latest', file='testUpdateLimitSizeAddDelete_filesremote')
@GET('http://localhost/source/osctest/limitsize/exists', file='testUpdateLimitSizeAddDelete_exists')
@GET('http://localhost/source/osctest/limitsize/_meta', file='meta.xml')
def testUpdateLimitSizeAddDelete(self):
"""
a new file (exists) was added to the remote package with
size < limit_size and one file (nochange) was deleted from the
remote package (local file 'nochange' is modified). Additionally
files which didn't change are removed the local wc due to the
size constraint.
"""
self.__change_to_pkg('limitsize')
osc.core.Package('.').update(limit_size=10)
self.assertTrue(len(EXPECTED_REQUESTS) == 0)
exp = 'A exists\nD bigfile\nD foo\nD merge\nD nochange\nAt revision 2.\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self.assertFalse(os.path.exists(os.path.join('.osc', 'bigfile')))
self.assertFalse(os.path.exists('bigfile'))
self.assertFalse(os.path.exists(os.path.join('.osc', 'foo')))
self.assertFalse(os.path.exists('foo'))
self.assertFalse(os.path.exists(os.path.join('.osc', 'merge')))
self.assertFalse(os.path.exists('merge'))
# exists because local version is modified
self.assertTrue(os.path.exists('nochange'))
self.__check_digests('testUpdateLimitSizeAddDelete_files', 'bigfile', 'foo', 'merge', 'nochange')
# tests to recover from an aborted/broken update
@GET('http://localhost/source/osctest/simple/foo?rev=2', file='testUpdateResume_foo')
@ -244,11 +287,13 @@ class TestUpdate(unittest.TestCase):
def __change_to_pkg(self, name):
os.chdir(os.path.join(self.tmpdir, 'osctest', name))
def __check_digests(self, fname):
def __check_digests(self, fname, *skipfiles):
fname = os.path.join(FIXTURES_DIR, fname)
self.assertEqual(open(os.path.join('.osc', '_files'), 'r').read(), open(fname, 'r').read())
root = ET.parse(fname).getroot()
for i in root.findall('entry'):
if i.get('name') in skipfiles:
continue
self.assertTrue(os.path.exists(os.path.join('.osc', i.get('name'))))
self.assertEqual(osc.core.dgst(os.path.join('.osc', i.get('name'))), i.get('md5'))

View File

@ -0,0 +1 @@
http://localhost

View File

@ -0,0 +1,5 @@
<directory name="limitsize" rev="1" srcmd5="2df1eacfe03a3bec2112529e7f4dc39a" vrev="1">
<entry md5="0d62ceea6020d75154078a20d8c9f9ba" mtime="1282047302" name="foo" size="23" />
<entry md5="17b9e9e1a032ed44e7a584dc6303ffa8" mtime="1282047303" name="merge" size="48" />
<entry md5="7efa70f68983fad1cf487f69dedf93e9" mtime="1282047303" name="nochange" size="25" />
</directory>

View File

@ -0,0 +1 @@
1.0

View File

@ -0,0 +1 @@
limitsize

View File

@ -0,0 +1 @@
osctest

View File

@ -0,0 +1 @@
This is a simple test.

View File

@ -0,0 +1,4 @@
Is it
possible to
merge this file?
I hope so...

View File

@ -0,0 +1 @@
This file didn't change.

View File

@ -0,0 +1 @@
This is a simple test.

View File

@ -0,0 +1,4 @@
Is it
possible to
merge this file?
I hope so...

View File

@ -0,0 +1,2 @@
This file didn't change but
is modified.

View File

@ -0,0 +1 @@
small

View File

@ -0,0 +1,6 @@
<directory name="foo" rev="2" srcmd5="018a80019e08143e7ae324c778873d62" vrev="2">
<entry md5="ed955c917012307d982b7cdd5799ff1a" mtime="1282320398" name="bigfile" size="69" skipped="true" />
<entry md5="d15dbfcb847653913855e21370d83af1" mtime="1282553634" name="exists" size="6" />
<entry md5="0d62ceea6020d75154078a20d8c9f9ba" mtime="1282320303" name="foo" size="23" skipped="true" />
<entry md5="17b9e9e1a032ed44e7a584dc6303ffa8" mtime="1282320303" name="merge" size="48" skipped="true" />
</directory>

View File

@ -0,0 +1,6 @@
<directory name="foo" rev="2" vrev="2" srcmd5="018a80019e08143e7ae324c778873d62">
<entry name="bigfile" md5="ed955c917012307d982b7cdd5799ff1a" size="69" mtime="1282320398" />
<entry name="exists" md5="d15dbfcb847653913855e21370d83af1" size="6" mtime="1282553634" />
<entry name="foo" md5="0d62ceea6020d75154078a20d8c9f9ba" size="23" mtime="1282320303" />
<entry name="merge" md5="17b9e9e1a032ed44e7a584dc6303ffa8" size="48" mtime="1282320303" />
</directory>

View File

@ -0,0 +1,6 @@
<directory name="limitsize" rev="2" srcmd5="e51a3133d3d3eb2a48e06efb79e2d503" vrev="2">
<entry md5="ed955c917012307d982b7cdd5799ff1a" mtime="1282320398" name="bigfile" size="69" skipped="true" />
<entry md5="0d62ceea6020d75154078a20d8c9f9ba" mtime="1282320303" name="foo" size="23" />
<entry md5="17b9e9e1a032ed44e7a584dc6303ffa8" mtime="1282320303" name="merge" size="48" />
<entry md5="7efa70f68983fad1cf487f69dedf93e9" mtime="1282047303" name="nochange" size="25" />
</directory>

View File

@ -0,0 +1,6 @@
<directory name="limitsize" rev="2" vrev="2" srcmd5="e51a3133d3d3eb2a48e06efb79e2d503">
<entry name="bigfile" md5="ed955c917012307d982b7cdd5799ff1a" size="69" mtime="1282320398" />
<entry name="foo" md5="0d62ceea6020d75154078a20d8c9f9ba" size="23" mtime="1282320303" />
<entry name="merge" md5="17b9e9e1a032ed44e7a584dc6303ffa8" size="48" mtime="1282320303" />
<entry name="nochange" md5="7efa70f68983fad1cf487f69dedf93e9" size="25" mtime="1282047303" />
</directory>