APT

Merge lp:~mvo/apt/lp1045704 into lp:~mvo/apt/mvo

Proposed by Michael Vogt
Status: Rejected
Rejected by: Michael Vogt
Proposed branch: lp:~mvo/apt/lp1045704
Merge into: lp:~mvo/apt/mvo
Diff against target: 138 lines (+91/-0)
5 files modified
apt-pkg/contrib/fileutl.cc (+31/-0)
apt-pkg/contrib/fileutl.h (+3/-0)
apt-pkg/pkgcachegen.cc (+9/-0)
test/libapt/fileutl_test.cc (+42/-0)
test/libapt/makefile (+6/-0)
To merge this branch: bzr merge lp:~mvo/apt/lp1045704
Reviewer Review Type Date Requested Status
Michael Vogt Pending
Review via email: mp+122651@code.launchpad.net

Description of the change

Fix bug #1045704 by removing old leftovers from the atomic writes.

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

This will fix the problem at hand. We could make it more generic by:
- make the extension for Atomic writes more uniq (e.g. appending .apt-atomic-write.XXXXX)
- do the Glob()/unlink() on all previous instances of any $filename.apt-atomic.*

This sounds a little bit dangerous this is why I did not do it this way currently, but
its probably a good idea.

Unmerged revisions

1846. By Michael Vogt

apt-pkg/pkgcachegen.cc: use the new Glob() function to clean the old atomic write leftovers

1845. By Michael Vogt

add "Glob()" to fileutl

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'apt-pkg/contrib/fileutl.cc'
--- apt-pkg/contrib/fileutl.cc 2012-03-06 09:53:35 +0000
+++ apt-pkg/contrib/fileutl.cc 2012-09-04 10:37:18 +0000
@@ -41,6 +41,8 @@
41#include <dirent.h>41#include <dirent.h>
42#include <signal.h>42#include <signal.h>
43#include <errno.h>43#include <errno.h>
44#include <glob.h>
45
44#include <set>46#include <set>
45#include <algorithm>47#include <algorithm>
4648
@@ -1552,3 +1554,32 @@
1552 /*}}}*/1554 /*}}}*/
15531555
1554gzFile FileFd::gzFd() { return (gzFile) d->gz; }1556gzFile FileFd::gzFd() { return (gzFile) d->gz; }
1557
1558
1559// Glob - wrapper around "glob()" /*{{{*/
1560// ---------------------------------------------------------------------
1561/* */
1562std::vector<std::string> Glob(std::string const &pattern, int flags)
1563{
1564 std::vector<std::string> result;
1565 glob_t globbuf;
1566 int glob_res, i;
1567
1568 glob_res = glob(pattern.c_str(), flags, NULL, &globbuf);
1569
1570 if (glob_res != 0)
1571 {
1572 if(glob_res != GLOB_NOMATCH) {
1573 _error->Errno("glob", "Problem with glob");
1574 return result;
1575 }
1576 }
1577
1578 // append results
1579 for(i=0;i<globbuf.gl_pathc;i++)
1580 result.push_back(string(globbuf.gl_pathv[i]));
1581
1582 globfree(&globbuf);
1583 return result;
1584}
1585 /*}}}*/
15551586
=== modified file 'apt-pkg/contrib/fileutl.h'
--- apt-pkg/contrib/fileutl.h 2012-02-11 21:36:03 +0000
+++ apt-pkg/contrib/fileutl.h 2012-09-04 10:37:18 +0000
@@ -186,4 +186,7 @@
186std::string flExtension(std::string File);186std::string flExtension(std::string File);
187std::string flCombine(std::string Dir,std::string File);187std::string flCombine(std::string Dir,std::string File);
188188
189// simple c++ glob
190std::vector<std::string> Glob(std::string const &pattern, int flags=0);
191
189#endif192#endif
190193
=== modified file 'apt-pkg/pkgcachegen.cc'
--- apt-pkg/pkgcachegen.cc 2011-12-15 08:13:21 +0000
+++ apt-pkg/pkgcachegen.cc 2012-09-04 10:37:18 +0000
@@ -1270,6 +1270,15 @@
1270 if (Writeable == false && AllowMem == false && CacheFile.empty() == false)1270 if (Writeable == false && AllowMem == false && CacheFile.empty() == false)
1271 return _error->Error(_("Unable to write to %s"),flNotFile(CacheFile).c_str());1271 return _error->Error(_("Unable to write to %s"),flNotFile(CacheFile).c_str());
12721272
1273 // Clean old leftover tempfiles from the AtomicWrite
1274 std::vector<std::string> tmp_files, tmp_files2;
1275 std::vector<std::string>::const_iterator it;
1276 tmp_files = Glob(CacheFile+".*");
1277 tmp_files2 = Glob(SrcCacheFile+".*");
1278 tmp_files.insert(tmp_files.end(), tmp_files2.begin(), tmp_files2.end());
1279 for (it=tmp_files.begin();it != tmp_files.end(); it++)
1280 unlink((*it).c_str());
1281
1273 if (Progress != NULL)1282 if (Progress != NULL)
1274 Progress->OverallProgress(0,1,1,_("Reading package lists"));1283 Progress->OverallProgress(0,1,1,_("Reading package lists"));
12751284
12761285
=== added file 'test/libapt/fileutl_test.cc'
--- test/libapt/fileutl_test.cc 1970-01-01 00:00:00 +0000
+++ test/libapt/fileutl_test.cc 2012-09-04 10:37:18 +0000
@@ -0,0 +1,42 @@
1#include <apt-pkg/error.h>
2#include <apt-pkg/fileutl.h>
3
4#include "assert.h"
5#include <string>
6#include <vector>
7
8#include <stdio.h>
9#include <iostream>
10#include <stdlib.h>
11
12
13int main(int argc,char *argv[])
14{
15 std::vector<std::string> files;
16
17 // normal match
18 files = Glob("*.lst");
19 if (files.size() != 1)
20 {
21 _error->DumpErrors();
22 return 1;
23 }
24
25 // not there
26 files = Glob("xxxyyyzzz");
27 if (files.size() != 0 || _error->PendingError())
28 {
29 _error->DumpErrors();
30 return 1;
31 }
32
33 // many matches (number is a bit random)
34 files = Glob("*.cc");
35 if (files.size() < 10)
36 {
37 _error->DumpErrors();
38 return 1;
39 }
40
41 return 0;
42}
043
=== modified file 'test/libapt/makefile'
--- test/libapt/makefile 2011-12-11 01:55:20 +0000
+++ test/libapt/makefile 2012-09-04 10:37:18 +0000
@@ -80,3 +80,9 @@
80SLIBS = -lapt-pkg80SLIBS = -lapt-pkg
81SOURCE = cdromfindpackages_test.cc81SOURCE = cdromfindpackages_test.cc
82include $(PROGRAM_H)82include $(PROGRAM_H)
83
84# test fileutls
85PROGRAM = FileUtl${BASENAME}
86SLIBS = -lapt-pkg
87SOURCE = fileutl_test.cc
88include $(PROGRAM_H)

Subscribers

People subscribed via source and target branches

to all changes: