]>
git.saurik.com Git - apt.git/blob - methods/file.cc
f2bcf371a1fa6e1386fbf9a1bcb6b5118a972439
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: file.cc,v 1.7 1999/01/18 06:20:08 jgg 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 /*{{{*/
16 #include <apt-pkg/acquire-method.h>
17 #include <apt-pkg/error.h>
23 class FileMethod
: public pkgAcqMethod
25 virtual bool Fetch(FetchItem
*Itm
);
29 FileMethod() : pkgAcqMethod("1.0",SingleInstance
| LocalOnly
) {};
32 // FileMethod::Fetch - Fetch a file /*{{{*/
33 // ---------------------------------------------------------------------
35 bool FileMethod::Fetch(FetchItem
*Itm
)
38 string File
= Get
.Path
;
40 if (Get
.Host
.empty() == false)
41 return _error
->Error("Invalid URI, local URIS must not start with //");
43 // See if the file exists
45 if (stat(File
.c_str(),&Buf
) == 0)
47 Res
.Size
= Buf
.st_size
;
49 Res
.LastModified
= Buf
.st_mtime
;
51 if (Itm
->LastModified
== Buf
.st_mtime
)
55 // See if we can compute a file without a .gz exentsion
56 string::size_type Pos
= File
.rfind(".gz");
57 if (Pos
+ 3 == File
.length())
59 File
= string(File
,0,Pos
);
60 if (stat(File
.c_str(),&Buf
) == 0)
63 AltRes
.Size
= Buf
.st_size
;
64 AltRes
.Filename
= File
;
65 AltRes
.LastModified
= Buf
.st_mtime
;
66 AltRes
.IMSHit
= false;
67 if (Itm
->LastModified
== Buf
.st_mtime
)
75 if (Res
.Filename
.empty() == true)
76 return _error
->Error("File not found");