]> git.saurik.com Git - apt.git/blob - methods/aptmethod.h
don't try pipelining if server closes connections
[apt.git] / methods / aptmethod.h
1 #ifndef APT_APTMETHOD_H
2 #define APT_APTMETHOD_H
3
4 #include <apt-pkg/acquire-method.h>
5 #include <apt-pkg/configuration.h>
6 #include <apt-pkg/error.h>
7
8 #include <string>
9
10 #include <sys/time.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <unistd.h>
14
15 #include <apti18n.h>
16
17 class aptMethod : public pkgAcqMethod
18 {
19 char const * const Binary;
20
21 public:
22 virtual bool Configuration(std::string Message) APT_OVERRIDE
23 {
24 if (pkgAcqMethod::Configuration(Message) == false)
25 return false;
26
27 std::string const conf = std::string("Binary::") + Binary;
28 _config->MoveSubTree(conf.c_str(), NULL);
29
30 DropPrivsOrDie();
31
32 return true;
33 }
34
35 bool CalculateHashes(FetchItem const * const Itm, FetchResult &Res) const
36 {
37 Hashes Hash(Itm->ExpectedHashes);
38 FileFd Fd;
39 if (Fd.Open(Res.Filename, FileFd::ReadOnly) == false || Hash.AddFD(Fd) == false)
40 return false;
41 Res.TakeHashes(Hash);
42 return true;
43 }
44
45 void Warning(const char *Format,...)
46 {
47 va_list args;
48 va_start(args,Format);
49 PrintStatus("104 Warning", Format, args);
50 va_end(args);
51 }
52
53 bool TransferModificationTimes(char const * const From, char const * const To, time_t &LastModified)
54 {
55 if (strcmp(To, "/dev/null") == 0)
56 return true;
57
58 struct stat Buf2;
59 if (lstat(To, &Buf2) != 0 || S_ISLNK(Buf2.st_mode))
60 return true;
61
62 struct stat Buf;
63 if (stat(From, &Buf) != 0)
64 return _error->Errno("stat",_("Failed to stat"));
65
66 // we don't use utimensat here for compatibility reasons: #738567
67 struct timeval times[2];
68 times[0].tv_sec = Buf.st_atime;
69 LastModified = times[1].tv_sec = Buf.st_mtime;
70 times[0].tv_usec = times[1].tv_usec = 0;
71 if (utimes(To, times) != 0)
72 return _error->Errno("utimes",_("Failed to set modification time"));
73 return true;
74 }
75
76 aptMethod(char const * const Binary, char const * const Ver, unsigned long const Flags) :
77 pkgAcqMethod(Ver, Flags), Binary(Binary)
78 {}
79 };
80
81 #endif