summaryrefslogtreecommitdiff
path: root/methods
diff options
context:
space:
mode:
Diffstat (limited to 'methods')
-rw-r--r--methods/copy.cc14
-rw-r--r--methods/ftp.cc18
-rw-r--r--methods/gpgv.cc1
-rw-r--r--methods/gzip.cc22
-rw-r--r--methods/http.cc1
-rw-r--r--methods/https.cc6
-rw-r--r--methods/rred.cc68
-rw-r--r--methods/rsh.cc18
-rw-r--r--methods/server.cc12
9 files changed, 66 insertions, 94 deletions
diff --git a/methods/copy.cc b/methods/copy.cc
index 744cc2b51..f2a8f9ed8 100644
--- a/methods/copy.cc
+++ b/methods/copy.cc
@@ -18,6 +18,7 @@
#include <apt-pkg/hashes.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <unistd.h>
#include <apti18n.h>
/*}}}*/
@@ -70,18 +71,15 @@ bool CopyMethod::Fetch(FetchItem *Itm)
}
From.Close();
+ To.Close();
// Transfer the modification times
- struct timespec times[2];
+ struct timeval times[2];
times[0].tv_sec = Buf.st_atime;
times[1].tv_sec = Buf.st_mtime;
- times[0].tv_nsec = times[1].tv_nsec = 0;
- if (futimens(To.Fd(), times) != 0)
- {
- To.OpFail();
- return _error->Errno("futimens",_("Failed to set modification time"));
- }
- To.Close();
+ times[0].tv_usec = times[1].tv_usec = 0;
+ if (utimes(Res.Filename.c_str(), times) != 0)
+ return _error->Errno("utimes",_("Failed to set modification time"));
Hashes Hash;
FileFd Fd(Res.Filename, FileFd::ReadOnly);
diff --git a/methods/ftp.cc b/methods/ftp.cc
index 2d05364d5..70bf4f607 100644
--- a/methods/ftp.cc
+++ b/methods/ftp.cc
@@ -954,11 +954,11 @@ void FtpMethod::SigTerm(int)
_exit(100);
// Timestamp
- struct timespec times[2];
+ struct timeval times[2];
times[0].tv_sec = FailTime;
times[1].tv_sec = FailTime;
- times[0].tv_nsec = times[1].tv_nsec = 0;
- futimens(FailFd, times);
+ times[0].tv_usec = times[1].tv_usec = 0;
+ utimes(FailFile.c_str(), times);
close(FailFd);
@@ -1062,11 +1062,11 @@ bool FtpMethod::Fetch(FetchItem *Itm)
Fd.Close();
// Timestamp
- struct timespec times[2];
+ struct timeval times[2];
times[0].tv_sec = FailTime;
times[1].tv_sec = FailTime;
- times[0].tv_nsec = times[1].tv_nsec = 0;
- futimens(FailFd, times);
+ times[0].tv_usec = times[1].tv_usec = 0;
+ utimes(FailFile.c_str(), times);
// If the file is missing we hard fail and delete the destfile
// otherwise transient fail
@@ -1081,11 +1081,11 @@ bool FtpMethod::Fetch(FetchItem *Itm)
Res.Size = Fd.Size();
// Timestamp
- struct timespec times[2];
+ struct timeval times[2];
times[0].tv_sec = FailTime;
times[1].tv_sec = FailTime;
- times[0].tv_nsec = times[1].tv_nsec = 0;
- futimens(Fd.Fd(), times);
+ times[0].tv_usec = times[1].tv_usec = 0;
+ utimes(Fd.Name().c_str(), times);
FailFd = -1;
}
diff --git a/methods/gpgv.cc b/methods/gpgv.cc
index ea8a26fd4..25bf64ddd 100644
--- a/methods/gpgv.cc
+++ b/methods/gpgv.cc
@@ -8,7 +8,6 @@
#include <apt-pkg/configuration.h>
#include <apt-pkg/gpgv.h>
-#include <utime.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
diff --git a/methods/gzip.cc b/methods/gzip.cc
index f1edb353b..a2844e969 100644
--- a/methods/gzip.cc
+++ b/methods/gzip.cc
@@ -18,6 +18,7 @@
#include <apt-pkg/hashes.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
@@ -93,6 +94,8 @@ bool GzipMethod::Fetch(FetchItem *Itm)
}
From.Close();
+ Res.Size = To.FileSize();
+ To.Close();
if (Failed == true)
return false;
@@ -102,23 +105,14 @@ bool GzipMethod::Fetch(FetchItem *Itm)
if (stat(Path.c_str(),&Buf) != 0)
return _error->Errno("stat",_("Failed to stat"));
- struct timespec times[2];
+ struct timeval times[2];
times[0].tv_sec = Buf.st_atime;
- times[1].tv_sec = Buf.st_mtime;
- times[0].tv_nsec = times[1].tv_nsec = 0;
- if (futimens(To.Fd(), times) != 0)
- {
- To.OpFail();
- return _error->Errno("futimens",_("Failed to set modification time"));
- }
- Res.Size = To.FileSize();
- To.Close();
-
- if (stat(Itm->DestFile.c_str(),&Buf) != 0)
- return _error->Errno("stat",_("Failed to stat"));
+ Res.LastModified = times[1].tv_sec = Buf.st_mtime;
+ times[0].tv_usec = times[1].tv_usec = 0;
+ if (utimes(Itm->DestFile.c_str(), times) != 0)
+ return _error->Errno("utimes",_("Failed to set modification time"));
// Return a Done response
- Res.LastModified = Buf.st_mtime;
Res.TakeHashes(Hash);
URIDone(Res);
diff --git a/methods/http.cc b/methods/http.cc
index e1390afcb..96c4e3ca0 100644
--- a/methods/http.cc
+++ b/methods/http.cc
@@ -36,7 +36,6 @@
#include <sys/stat.h>
#include <sys/time.h>
-#include <utime.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
diff --git a/methods/https.cc b/methods/https.cc
index e16e36339..146b2bfb8 100644
--- a/methods/https.cc
+++ b/methods/https.cc
@@ -404,11 +404,11 @@ bool HttpsMethod::Fetch(FetchItem *Itm)
curl_easy_getinfo(curl, CURLINFO_FILETIME, &Res.LastModified);
if (Res.LastModified != -1)
{
- struct timespec times[2];
+ struct timeval times[2];
times[0].tv_sec = Res.LastModified;
times[1].tv_sec = Res.LastModified;
- times[0].tv_nsec = times[1].tv_nsec = 0;
- futimens(File->Fd(), times);
+ times[0].tv_usec = times[1].tv_usec = 0;
+ utimes(File->Name().c_str(), times);
}
else
Res.LastModified = resultStat.st_mtime;
diff --git a/methods/rred.cc b/methods/rred.cc
index d17ab110d..fe7ef7322 100644
--- a/methods/rred.cc
+++ b/methods/rred.cc
@@ -20,12 +20,13 @@
#include <vector>
#include <iterator>
+#include <fcntl.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
-#include <utime.h>
+#include <sys/time.h>
#include <apti18n.h>
@@ -37,11 +38,9 @@ class MemBlock {
char *free;
struct MemBlock *next;
- MemBlock(size_t size)
+ MemBlock(size_t size) : size(size), next(NULL)
{
free = start = new char[size];
- size = size;
- next = NULL;
}
size_t avail(void) { return size - (free - start); }
@@ -157,7 +156,7 @@ class FileChanges {
#ifdef POSDEBUG
size_t cpos = 0;
std::list<struct Change>::iterator x;
- for (x = changes.begin(); x != where; x++) {
+ for (x = changes.begin(); x != where; ++x) {
assert(x != changes.end());
cpos += x->offset + x->add_cnt;
}
@@ -208,7 +207,7 @@ class FileChanges {
left();
}
std::list<struct Change>::iterator next = where;
- next++;
+ ++next;
while (next != changes.end() && next->offset == 0) {
where->del_cnt += next->del_cnt;
@@ -221,7 +220,7 @@ class FileChanges {
where->add_cnt = next->add_cnt;
next = changes.erase(next);
} else {
- next++;
+ ++next;
}
}
}
@@ -261,7 +260,7 @@ class FileChanges {
if (where != changes.end())
where->offset -= offset;
changes.insert(where, Change(offset));
- where--;
+ --where;
assert(pos_is_okay());
}
@@ -284,26 +283,10 @@ class FileChanges {
before.add_len -= where->add_len;
changes.insert(where, before);
- where--;
+ --where;
assert(pos_is_okay());
}
- size_t check_next_offset(size_t max)
- {
- assert(pos_is_okay());
- if (max > 0)
- {
- where++;
- if (where != changes.end()) {
- if (where->offset < max)
- max = where->offset;
- }
- where--;
- assert(pos_is_okay());
- }
- return max;
- }
-
void delete_lines(size_t cnt)
{
std::list<struct Change>::iterator x = where;
@@ -317,7 +300,7 @@ class FileChanges {
x->skip_lines(del);
cnt -= del;
- x++;
+ ++x;
if (x == changes.end()) {
del = cnt;
} else {
@@ -334,7 +317,7 @@ class FileChanges {
void left(void) {
assert(pos_is_okay());
- where--;
+ --where;
pos -= where->offset + where->add_cnt;
assert(pos_is_okay());
}
@@ -342,7 +325,7 @@ class FileChanges {
void right(void) {
assert(pos_is_okay());
pos += where->offset + where->add_cnt;
- where++;
+ ++where;
assert(pos_is_okay());
}
};
@@ -378,11 +361,10 @@ class Patch {
static void dump_lines(FILE *o, FILE *i, size_t n, Hashes *hash)
{
char buffer[BLOCK_SIZE];
- size_t l;
while (n > 0) {
if (fgets(buffer, sizeof(buffer), i) == 0)
buffer[0] = '\0';
- l = strlen(buffer);
+ size_t const l = strlen(buffer);
if (l == 0 || buffer[l-1] == '\n')
n--;
retry_fwrite(buffer, l, o, hash);
@@ -392,11 +374,10 @@ class Patch {
static void skip_lines(FILE *i, int n)
{
char buffer[BLOCK_SIZE];
- size_t l;
while (n > 0) {
if (fgets(buffer, sizeof(buffer), i) == 0)
buffer[0] = '\0';
- l = strlen(buffer);
+ size_t const l = strlen(buffer);
if (l == 0 || buffer[l-1] == '\n')
n--;
}
@@ -490,14 +471,14 @@ class Patch {
{
size_t line = 0;
std::list<struct Change>::reverse_iterator ch;
- for (ch = filechanges.rbegin(); ch != filechanges.rend(); ch++) {
+ for (ch = filechanges.rbegin(); ch != filechanges.rend(); ++ch) {
line += ch->offset + ch->del_cnt;
}
- for (ch = filechanges.rbegin(); ch != filechanges.rend(); ch++) {
+ for (ch = filechanges.rbegin(); ch != filechanges.rend(); ++ch) {
std::list<struct Change>::reverse_iterator mg_i, mg_e = ch;
while (ch->del_cnt == 0 && ch->offset == 0)
- ch++;
+ ++ch;
line -= ch->del_cnt;
if (ch->add_cnt > 0) {
if (ch->del_cnt == 0) {
@@ -526,7 +507,7 @@ class Patch {
void apply_against_file(FILE *out, FILE *in, Hashes *hash = NULL)
{
std::list<struct Change>::iterator ch;
- for (ch = filechanges.begin(); ch != filechanges.end(); ch++) {
+ for (ch = filechanges.begin(); ch != filechanges.end(); ++ch) {
dump_lines(out, in, ch->offset, hash);
skip_lines(in, ch->del_cnt);
dump_mem(out, ch->add, ch->add_len, hash);
@@ -575,7 +556,7 @@ class RredMethod : public pkgAcqMethod {
std::string patch_name;
for (std::vector<std::string>::iterator I = patchpaths.begin();
I != patchpaths.end();
- I++)
+ ++I)
{
patch_name = *I;
if (Debug == true)
@@ -617,11 +598,12 @@ class RredMethod : public pkgAcqMethod {
stat(patch_name.c_str(), &bufpatch) != 0)
return _error->Errno("stat", _("Failed to stat"));
- struct utimbuf timebuf;
- timebuf.actime = bufbase.st_atime;
- timebuf.modtime = bufpatch.st_mtime;
- if (utime(Itm->DestFile.c_str(), &timebuf) != 0)
- return _error->Errno("utime", _("Failed to set modification time"));
+ struct timeval times[2];
+ times[0].tv_sec = bufbase.st_atime;
+ times[1].tv_sec = bufpatch.st_mtime;
+ times[0].tv_usec = times[1].tv_usec = 0;
+ if (utimes(Itm->DestFile.c_str(), times) != 0)
+ return _error->Errno("utimes",_("Failed to set modification time"));
if (stat(Itm->DestFile.c_str(), &bufbase) != 0)
return _error->Errno("stat", _("Failed to stat"));
@@ -635,7 +617,7 @@ class RredMethod : public pkgAcqMethod {
}
public:
- RredMethod() : pkgAcqMethod("2.0",SingleInstance | SendConfig) {}
+ RredMethod() : pkgAcqMethod("2.0",SingleInstance | SendConfig), Debug(false) {}
};
int main(int argc, char **argv)
diff --git a/methods/rsh.cc b/methods/rsh.cc
index a441220bf..4e1aaea26 100644
--- a/methods/rsh.cc
+++ b/methods/rsh.cc
@@ -396,11 +396,11 @@ void RSHMethod::SigTerm(int sig)
_exit(100);
// Transfer the modification times
- struct timespec times[2];
+ struct timeval times[2];
times[0].tv_sec = FailTime;
times[1].tv_sec = FailTime;
- times[0].tv_nsec = times[1].tv_nsec = 0;
- futimens(FailFd, times);
+ times[0].tv_usec = times[1].tv_usec = 0;
+ utimes(FailFile.c_str(), times);
close(FailFd);
_exit(100);
@@ -488,11 +488,11 @@ bool RSHMethod::Fetch(FetchItem *Itm)
Fd.Close();
// Timestamp
- struct timespec times[2];
+ struct timeval times[2];
times[0].tv_sec = FailTime;
times[1].tv_sec = FailTime;
- times[0].tv_nsec = times[1].tv_nsec = 0;
- futimens(FailFd, times);
+ times[0].tv_usec = times[1].tv_usec = 0;
+ utimes(FailFile.c_str(), times);
// If the file is missing we hard fail otherwise transient fail
if (Missing == true)
@@ -502,11 +502,11 @@ bool RSHMethod::Fetch(FetchItem *Itm)
}
Res.Size = Fd.Size();
- struct timespec times[2];
+ struct timeval times[2];
times[0].tv_sec = FailTime;
times[1].tv_sec = FailTime;
- times[0].tv_nsec = times[1].tv_nsec = 0;
- futimens(Fd.Fd(), times);
+ times[0].tv_usec = times[1].tv_usec = 0;
+ utimes(Fd.Name().c_str(), times);
FailFd = -1;
}
diff --git a/methods/server.cc b/methods/server.cc
index e12c23c07..76faa7e7f 100644
--- a/methods/server.cc
+++ b/methods/server.cc
@@ -369,11 +369,11 @@ void ServerMethod::SigTerm(int)
if (FailFd == -1)
_exit(100);
- struct timespec times[2];
+ struct timeval times[2];
times[0].tv_sec = FailTime;
times[1].tv_sec = FailTime;
- times[0].tv_nsec = times[1].tv_nsec = 0;
- futimens(FailFd, times);
+ times[0].tv_usec = times[1].tv_usec = 0;
+ utimes(FailFile.c_str(), times);
close(FailFd);
_exit(100);
@@ -539,10 +539,10 @@ int ServerMethod::Loop()
File = 0;
// Timestamp
- struct timespec times[2];
+ struct timeval times[2];
times[0].tv_sec = times[1].tv_sec = Server->Date;
- times[0].tv_nsec = times[1].tv_nsec = 0;
- utimensat(AT_FDCWD, Queue->DestFile.c_str(), times, AT_SYMLINK_NOFOLLOW);
+ times[0].tv_usec = times[1].tv_usec = 0;
+ utimes(Queue->DestFile.c_str(), times);
// Send status to APT
if (Result == true)