]>
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 /*{{{*/
14 #include <apt-pkg/fileutl.h>
15 #include <apt-pkg/strutl.h>
16 #include <apt-pkg/acquire-method.h>
17 #include <apt-pkg/error.h>
18 #include <apt-pkg/hashes.h>
27 class CopyMethod
: public pkgAcqMethod
29 virtual bool Fetch(FetchItem
*Itm
);
33 CopyMethod() : pkgAcqMethod("1.0",SingleInstance
) {};
36 // CopyMethod::Fetch - Fetch a file /*{{{*/
37 // ---------------------------------------------------------------------
39 bool CopyMethod::Fetch(FetchItem
*Itm
)
42 std::string File
= Get
.Path
;
44 // Stat the file and send a start message
46 if (stat(File
.c_str(),&Buf
) != 0)
47 return _error
->Errno("stat",_("Failed to stat"));
49 // Forumulate a result and send a start message
51 Res
.Size
= Buf
.st_size
;
52 Res
.Filename
= Itm
->DestFile
;
53 Res
.LastModified
= Buf
.st_mtime
;
57 // See if the file exists
58 FileFd
From(File
,FileFd::ReadOnly
);
59 FileFd
To(Itm
->DestFile
,FileFd::WriteAtomic
);
61 if (_error
->PendingError() == true)
68 if (CopyFile(From
,To
) == false)
77 // Transfer the modification times
78 struct timeval times
[2];
79 times
[0].tv_sec
= Buf
.st_atime
;
80 times
[1].tv_sec
= Buf
.st_mtime
;
81 times
[0].tv_usec
= times
[1].tv_usec
= 0;
82 if (utimes(Res
.Filename
.c_str(), times
) != 0)
83 return _error
->Errno("utimes",_("Failed to set modification time"));
86 FileFd
Fd(Res
.Filename
, FileFd::ReadOnly
);
97 setlocale(LC_ALL
, "");