]>
git.saurik.com Git - apt.git/blob - methods/file.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: file.cc,v 1.9.2.1 2004/01/16 18:58:50 mdz Exp $
4 /* ######################################################################
6 File URI method for APT
8 This simply checks that the file specified exists, if so the relevent
9 information is returned. If a .gz filename is specified then the file
10 name with .gz removed will also be checked and information about it
11 will be returned in Alt-*
13 ##################################################################### */
15 // Include Files /*{{{*/
18 #include <apt-pkg/acquire-method.h>
19 #include <apt-pkg/error.h>
20 #include <apt-pkg/hashes.h>
21 #include <apt-pkg/fileutl.h>
22 #include <apt-pkg/strutl.h>
29 class FileMethod
: public pkgAcqMethod
31 virtual bool Fetch(FetchItem
*Itm
);
35 FileMethod() : pkgAcqMethod("1.0",SingleInstance
| LocalOnly
) {};
38 // FileMethod::Fetch - Fetch a file /*{{{*/
39 // ---------------------------------------------------------------------
41 bool FileMethod::Fetch(FetchItem
*Itm
)
44 std::string File
= Get
.Path
;
46 if (Get
.Host
.empty() == false)
47 return _error
->Error(_("Invalid URI, local URIS must not start with //"));
49 // See if the file exists
51 if (stat(File
.c_str(),&Buf
) == 0)
53 Res
.Size
= Buf
.st_size
;
55 Res
.LastModified
= Buf
.st_mtime
;
57 if (Itm
->LastModified
== Buf
.st_mtime
&& Itm
->LastModified
!= 0)
61 // See if we can compute a file without a .gz exentsion
62 std::string::size_type Pos
= File
.rfind(".gz");
63 if (Pos
+ 3 == File
.length())
65 File
= std::string(File
,0,Pos
);
66 if (stat(File
.c_str(),&Buf
) == 0)
69 AltRes
.Size
= Buf
.st_size
;
70 AltRes
.Filename
= File
;
71 AltRes
.LastModified
= Buf
.st_mtime
;
72 AltRes
.IMSHit
= false;
73 if (Itm
->LastModified
== Buf
.st_mtime
&& Itm
->LastModified
!= 0)
81 if (Res
.Filename
.empty() == true)
82 return _error
->Error(_("File not found"));
85 FileFd
Fd(Res
.Filename
, FileFd::ReadOnly
);
95 setlocale(LC_ALL
, "");