]>
git.saurik.com Git - apt.git/blob - methods/copy.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: copy.cc,v 1.4 1998/10/30 07:53:51 jgg Exp $
4 /* ######################################################################
6 Copy URI - This method takes a uri like a file: uri and copies it
7 to the destination file.
9 ##################################################################### */
11 // Include Files /*{{{*/
12 #include <apt-pkg/fileutl.h>
13 #include <apt-pkg/acquire-method.h>
14 #include <apt-pkg/error.h>
21 class CopyMethod
: public pkgAcqMethod
23 virtual bool Fetch(string Message
,URI Get
);
27 CopyMethod() : pkgAcqMethod("1.0",SingleInstance
) {};
30 // CopyMethod::Fetch - Fetch a file /*{{{*/
31 // ---------------------------------------------------------------------
33 bool CopyMethod::Fetch(string Message
,URI Get
)
35 string File
= Get
.Path
;
37 // See if the file exists
38 FileFd
From(File
,FileFd::ReadOnly
);
39 FileFd
To(DestFile
,FileFd::WriteEmpty
);
41 if (_error
->PendingError() == true)
45 if (CopyFile(From
,To
) == false)
51 // Transfer the modification times
53 if (stat(File
.c_str(),&Buf
) != 0)
56 return _error
->Errno("stat","Failed to stat");
59 struct utimbuf TimeBuf
;
60 TimeBuf
.actime
= Buf
.st_atime
;
61 TimeBuf
.modtime
= Buf
.st_mtime
;
62 if (utime(DestFile
.c_str(),&TimeBuf
) != 0)
65 return _error
->Errno("utime","Failed to set modification time");
68 // Forumulate a result
70 Res
.Size
= Buf
.st_size
;
71 Res
.Filename
= DestFile
;
72 Res
.LastModified
= Buf
.st_mtime
;