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
1=== modified file 'apt-pkg/contrib/fileutl.cc'
2--- apt-pkg/contrib/fileutl.cc 2012-03-06 09:53:35 +0000
3+++ apt-pkg/contrib/fileutl.cc 2012-09-04 10:37:18 +0000
4@@ -41,6 +41,8 @@
5 #include <dirent.h>
6 #include <signal.h>
7 #include <errno.h>
8+#include <glob.h>
9+
10 #include <set>
11 #include <algorithm>
12
13@@ -1552,3 +1554,32 @@
14 /*}}}*/
15
16 gzFile FileFd::gzFd() { return (gzFile) d->gz; }
17+
18+
19+// Glob - wrapper around "glob()" /*{{{*/
20+// ---------------------------------------------------------------------
21+/* */
22+std::vector<std::string> Glob(std::string const &pattern, int flags)
23+{
24+ std::vector<std::string> result;
25+ glob_t globbuf;
26+ int glob_res, i;
27+
28+ glob_res = glob(pattern.c_str(), flags, NULL, &globbuf);
29+
30+ if (glob_res != 0)
31+ {
32+ if(glob_res != GLOB_NOMATCH) {
33+ _error->Errno("glob", "Problem with glob");
34+ return result;
35+ }
36+ }
37+
38+ // append results
39+ for(i=0;i<globbuf.gl_pathc;i++)
40+ result.push_back(string(globbuf.gl_pathv[i]));
41+
42+ globfree(&globbuf);
43+ return result;
44+}
45+ /*}}}*/
46
47=== modified file 'apt-pkg/contrib/fileutl.h'
48--- apt-pkg/contrib/fileutl.h 2012-02-11 21:36:03 +0000
49+++ apt-pkg/contrib/fileutl.h 2012-09-04 10:37:18 +0000
50@@ -186,4 +186,7 @@
51 std::string flExtension(std::string File);
52 std::string flCombine(std::string Dir,std::string File);
53
54+// simple c++ glob
55+std::vector<std::string> Glob(std::string const &pattern, int flags=0);
56+
57 #endif
58
59=== modified file 'apt-pkg/pkgcachegen.cc'
60--- apt-pkg/pkgcachegen.cc 2011-12-15 08:13:21 +0000
61+++ apt-pkg/pkgcachegen.cc 2012-09-04 10:37:18 +0000
62@@ -1270,6 +1270,15 @@
63 if (Writeable == false && AllowMem == false && CacheFile.empty() == false)
64 return _error->Error(_("Unable to write to %s"),flNotFile(CacheFile).c_str());
65
66+ // Clean old leftover tempfiles from the AtomicWrite
67+ std::vector<std::string> tmp_files, tmp_files2;
68+ std::vector<std::string>::const_iterator it;
69+ tmp_files = Glob(CacheFile+".*");
70+ tmp_files2 = Glob(SrcCacheFile+".*");
71+ tmp_files.insert(tmp_files.end(), tmp_files2.begin(), tmp_files2.end());
72+ for (it=tmp_files.begin();it != tmp_files.end(); it++)
73+ unlink((*it).c_str());
74+
75 if (Progress != NULL)
76 Progress->OverallProgress(0,1,1,_("Reading package lists"));
77
78
79=== added file 'test/libapt/fileutl_test.cc'
80--- test/libapt/fileutl_test.cc 1970-01-01 00:00:00 +0000
81+++ test/libapt/fileutl_test.cc 2012-09-04 10:37:18 +0000
82@@ -0,0 +1,42 @@
83+#include <apt-pkg/error.h>
84+#include <apt-pkg/fileutl.h>
85+
86+#include "assert.h"
87+#include <string>
88+#include <vector>
89+
90+#include <stdio.h>
91+#include <iostream>
92+#include <stdlib.h>
93+
94+
95+int main(int argc,char *argv[])
96+{
97+ std::vector<std::string> files;
98+
99+ // normal match
100+ files = Glob("*.lst");
101+ if (files.size() != 1)
102+ {
103+ _error->DumpErrors();
104+ return 1;
105+ }
106+
107+ // not there
108+ files = Glob("xxxyyyzzz");
109+ if (files.size() != 0 || _error->PendingError())
110+ {
111+ _error->DumpErrors();
112+ return 1;
113+ }
114+
115+ // many matches (number is a bit random)
116+ files = Glob("*.cc");
117+ if (files.size() < 10)
118+ {
119+ _error->DumpErrors();
120+ return 1;
121+ }
122+
123+ return 0;
124+}
125
126=== modified file 'test/libapt/makefile'
127--- test/libapt/makefile 2011-12-11 01:55:20 +0000
128+++ test/libapt/makefile 2012-09-04 10:37:18 +0000
129@@ -80,3 +80,9 @@
130 SLIBS = -lapt-pkg
131 SOURCE = cdromfindpackages_test.cc
132 include $(PROGRAM_H)
133+
134+# test fileutls
135+PROGRAM = FileUtl${BASENAME}
136+SLIBS = -lapt-pkg
137+SOURCE = fileutl_test.cc
138+include $(PROGRAM_H)

Subscribers

People subscribed via source and target branches

to all changes: