]>
git.saurik.com Git - apt.git/blob - methods/file.cc
64490749b5fa2568beb288b4e10c14e7a444a4ac
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: file.cc,v 1.4 1998/10/30 07:53:52 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(string Message
,URI Get
);
29 FileMethod() : pkgAcqMethod("1.0",SingleInstance
) {};
32 // FileMethod::Fetch - Fetch a file /*{{{*/
33 // ---------------------------------------------------------------------
35 bool FileMethod::Fetch(string Message
,URI Get
)
37 string File
= Get
.Path
;
40 // See if the file exists
42 if (stat(File
.c_str(),&Buf
) == 0)
44 Res
.Size
= Buf
.st_size
;
46 Res
.LastModified
= Buf
.st_mtime
;
48 if (LastModified
== Buf
.st_mtime
)
52 // See if we can compute a file without a .gz exentsion
53 string::size_type Pos
= File
.rfind(".gz");
54 if (Pos
+ 3 == File
.length())
56 File
= string(File
,0,Pos
);
57 if (stat(File
.c_str(),&Buf
) == 0)
60 AltRes
.Size
= Buf
.st_size
;
61 AltRes
.Filename
= File
;
62 AltRes
.LastModified
= Buf
.st_mtime
;
63 AltRes
.IMSHit
= false;
64 if (LastModified
== Buf
.st_mtime
)
72 if (Res
.Filename
.empty() == true)
73 return _error
->Error("File not found");