]>
git.saurik.com Git - apt.git/blob - methods/file.cc
9fc4cd76c32b18f9adfb98318413eafde94354c1
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>
28 class FileMethod
: public pkgAcqMethod
30 virtual bool Fetch(FetchItem
*Itm
);
34 FileMethod() : pkgAcqMethod("1.0",SingleInstance
| LocalOnly
) {};
37 // FileMethod::Fetch - Fetch a file /*{{{*/
38 // ---------------------------------------------------------------------
40 bool FileMethod::Fetch(FetchItem
*Itm
)
43 string File
= Get
.Path
;
45 if (Get
.Host
.empty() == false)
46 return _error
->Error(_("Invalid URI, local URIS must not start with //"));
48 // See if the file exists
50 if (stat(File
.c_str(),&Buf
) == 0)
52 Res
.Size
= Buf
.st_size
;
54 Res
.LastModified
= Buf
.st_mtime
;
56 if (Itm
->LastModified
== Buf
.st_mtime
&& Itm
->LastModified
!= 0)
60 // See if we can compute a file without a .gz exentsion
61 string::size_type Pos
= File
.rfind(".gz");
62 if (Pos
+ 3 == File
.length())
64 File
= string(File
,0,Pos
);
65 if (stat(File
.c_str(),&Buf
) == 0)
68 AltRes
.Size
= Buf
.st_size
;
69 AltRes
.Filename
= File
;
70 AltRes
.LastModified
= Buf
.st_mtime
;
71 AltRes
.IMSHit
= false;
72 if (Itm
->LastModified
== Buf
.st_mtime
&& Itm
->LastModified
!= 0)
80 if (Res
.Filename
.empty() == true)
81 return _error
->Error(_("File not found"));
84 FileFd
Fd(Res
.Filename
, FileFd::ReadOnly
);
85 Hash
.AddFD(Fd
.Fd(), Fd
.Size());
94 setlocale(LC_ALL
, "");