]>
git.saurik.com Git - apt.git/blob - methods/copy.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: copy.cc,v 1.8 2004/01/07 20:39:38 mdz 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>
22 class CopyMethod
: public pkgAcqMethod
24 virtual bool Fetch(FetchItem
*Itm
);
28 CopyMethod() : pkgAcqMethod("1.0",SingleInstance
) {};
31 // CopyMethod::Fetch - Fetch a file /*{{{*/
32 // ---------------------------------------------------------------------
34 bool CopyMethod::Fetch(FetchItem
*Itm
)
37 string File
= Get
.Path
;
39 // Stat the file and send a start message
41 if (stat(File
.c_str(),&Buf
) != 0)
42 return _error
->Errno("stat",_("Failed to stat"));
44 // Forumulate a result and send a start message
46 Res
.Size
= Buf
.st_size
;
47 Res
.Filename
= Itm
->DestFile
;
48 Res
.LastModified
= Buf
.st_mtime
;
52 // See if the file exists
53 FileFd
From(File
,FileFd::ReadOnly
);
54 FileFd
To(Itm
->DestFile
,FileFd::WriteEmpty
);
56 if (_error
->PendingError() == true)
63 if (CopyFile(From
,To
) == false)
72 // Transfer the modification times
73 struct utimbuf TimeBuf
;
74 TimeBuf
.actime
= Buf
.st_atime
;
75 TimeBuf
.modtime
= Buf
.st_mtime
;
76 if (utime(Itm
->DestFile
.c_str(),&TimeBuf
) != 0)
79 return _error
->Errno("utime",_("Failed to set modification time"));
89 setlocale(LC_ALL
, "");