]>
git.saurik.com Git - apt.git/blob - methods/copy.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: copy.cc,v 1.6 1999/01/20 04:36:43 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(FetchItem
*Itm
);
27 CopyMethod() : pkgAcqMethod("1.0",SingleInstance
) {};
30 // CopyMethod::Fetch - Fetch a file /*{{{*/
31 // ---------------------------------------------------------------------
33 bool CopyMethod::Fetch(FetchItem
*Itm
)
36 string File
= Get
.Path
;
38 // Stat the file and send a start message
40 if (stat(File
.c_str(),&Buf
) != 0)
41 return _error
->Errno("stat","Failed to stat");
43 // Forumulate a result and send a start message
45 Res
.Size
= Buf
.st_size
;
46 Res
.Filename
= Itm
->DestFile
;
47 Res
.LastModified
= Buf
.st_mtime
;
51 // See if the file exists
52 FileFd
From(File
,FileFd::ReadOnly
);
53 FileFd
To(Itm
->DestFile
,FileFd::WriteEmpty
);
55 if (_error
->PendingError() == true)
62 if (CopyFile(From
,To
) == false)
71 // Transfer the modification times
72 struct utimbuf TimeBuf
;
73 TimeBuf
.actime
= Buf
.st_atime
;
74 TimeBuf
.modtime
= Buf
.st_mtime
;
75 if (utime(Itm
->DestFile
.c_str(),&TimeBuf
) != 0)
78 return _error
->Errno("utime","Failed to set modification time");