]>
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>
23 class CopyMethod
: public pkgAcqMethod
25 virtual bool Fetch(FetchItem
*Itm
);
29 CopyMethod() : pkgAcqMethod("1.0",SingleInstance
) {};
32 // CopyMethod::Fetch - Fetch a file /*{{{*/
33 // ---------------------------------------------------------------------
35 bool CopyMethod::Fetch(FetchItem
*Itm
)
38 string File
= Get
.Path
;
40 // Stat the file and send a start message
42 if (stat(File
.c_str(),&Buf
) != 0)
43 return _error
->Errno("stat",_("Failed to stat"));
45 // Forumulate a result and send a start message
47 Res
.Size
= Buf
.st_size
;
48 Res
.Filename
= Itm
->DestFile
;
49 Res
.LastModified
= Buf
.st_mtime
;
53 // See if the file exists
54 FileFd
From(File
,FileFd::ReadOnly
);
55 FileFd
To(Itm
->DestFile
,FileFd::WriteEmpty
);
57 if (_error
->PendingError() == true)
64 if (CopyFile(From
,To
) == false)
73 // Transfer the modification times
74 struct utimbuf TimeBuf
;
75 TimeBuf
.actime
= Buf
.st_atime
;
76 TimeBuf
.modtime
= Buf
.st_mtime
;
77 if (utime(Itm
->DestFile
.c_str(),&TimeBuf
) != 0)
80 return _error
->Errno("utime",_("Failed to set modification time"));
84 FileFd
Fd(Res
.Filename
, FileFd::ReadOnly
);
85 Hash
.AddFD(Fd
.Fd(), Fd
.Size());
94 setlocale(LC_ALL
, "");