]>
git.saurik.com Git - apt.git/blob - methods/copy.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: copy.cc,v 1.7.2.1 2004/01/16 18:58:50 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>
15 #include <apt-pkg/hashes.h>
16 #include <apt-pkg/fileutl.h>
24 class CopyMethod
: public pkgAcqMethod
26 virtual bool Fetch(FetchItem
*Itm
);
30 CopyMethod() : pkgAcqMethod("1.0",SingleInstance
) {};
33 // CopyMethod::Fetch - Fetch a file /*{{{*/
34 // ---------------------------------------------------------------------
36 bool CopyMethod::Fetch(FetchItem
*Itm
)
39 string File
= Get
.Path
;
41 // Stat the file and send a start message
43 if (stat(File
.c_str(),&Buf
) != 0)
44 return _error
->Errno("stat",_("Failed to stat"));
46 // Forumulate a result and send a start message
48 Res
.Size
= Buf
.st_size
;
49 Res
.Filename
= Itm
->DestFile
;
50 Res
.LastModified
= Buf
.st_mtime
;
54 // See if the file exists
55 FileFd
From(File
,FileFd::ReadOnly
);
56 FileFd
To(Itm
->DestFile
,FileFd::WriteEmpty
);
58 if (_error
->PendingError() == true)
65 if (CopyFile(From
,To
) == false)
74 // Transfer the modification times
75 struct utimbuf TimeBuf
;
76 TimeBuf
.actime
= Buf
.st_atime
;
77 TimeBuf
.modtime
= Buf
.st_mtime
;
78 if (utime(Itm
->DestFile
.c_str(),&TimeBuf
) != 0)
81 return _error
->Errno("utime",_("Failed to set modification time"));
85 FileFd
Fd(Res
.Filename
, FileFd::ReadOnly
);
86 Hash
.AddFD(Fd
.Fd(), Fd
.Size());
95 setlocale(LC_ALL
, "");