]>
Commit | Line | Data |
---|---|---|
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 <locale> | |
9 | #include <string> | |
10 | ||
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 | ||
18 | class aptMethod : public pkgAcqMethod | |
19 | { | |
20 | char const * const Binary; | |
21 | ||
22 | public: | |
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 | ||
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 | ||
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 | ||
77 | aptMethod(char const * const Binary, char const * const Ver, unsigned long const Flags) : | |
78 | pkgAcqMethod(Ver, Flags), Binary(Binary) | |
79 | { | |
80 | try { | |
81 | std::locale::global(std::locale("")); | |
82 | } catch (...) { | |
83 | setlocale(LC_ALL, ""); | |
84 | } | |
85 | } | |
86 | }; | |
87 | ||
88 | #endif |