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