]>
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 relevant
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>
30 class FileMethod
: public pkgAcqMethod
32 virtual bool Fetch(FetchItem
*Itm
);
36 FileMethod() : pkgAcqMethod("1.0",SingleInstance
| LocalOnly
) {};
39 // FileMethod::Fetch - Fetch a file /*{{{*/
40 // ---------------------------------------------------------------------
42 bool FileMethod::Fetch(FetchItem
*Itm
)
45 std::string File
= Get
.Path
;
47 if (Get
.Host
.empty() == false)
48 return _error
->Error(_("Invalid URI, local URIS must not start with //"));
50 // See if the file exists
52 if (stat(File
.c_str(),&Buf
) == 0)
54 Res
.Size
= Buf
.st_size
;
56 Res
.LastModified
= Buf
.st_mtime
;
58 if (Itm
->LastModified
== Buf
.st_mtime
&& Itm
->LastModified
!= 0)
62 // See if we can compute a file without a .gz exentsion
63 std::string::size_type Pos
= File
.rfind(".gz");
64 if (Pos
+ 3 == File
.length())
66 File
= std::string(File
,0,Pos
);
67 if (stat(File
.c_str(),&Buf
) == 0)
70 AltRes
.Size
= Buf
.st_size
;
71 AltRes
.Filename
= File
;
72 AltRes
.LastModified
= Buf
.st_mtime
;
73 AltRes
.IMSHit
= false;
74 if (Itm
->LastModified
== Buf
.st_mtime
&& Itm
->LastModified
!= 0)
82 if (Res
.Filename
.empty() == true)
83 return _error
->Error(_("File not found"));
86 FileFd
Fd(Res
.Filename
, FileFd::ReadOnly
);
96 setlocale(LC_ALL
, "");