]>
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                                                        /*{{{*/ 
  16 #include <apt-pkg/acquire-method.h> 
  17 #include <apt-pkg/error.h> 
  24 class FileMethod 
: public pkgAcqMethod
 
  26    virtual bool Fetch(FetchItem 
*Itm
); 
  30    FileMethod() : pkgAcqMethod("1.0",SingleInstance 
| LocalOnly
) {}; 
  33 // FileMethod::Fetch - Fetch a file                                     /*{{{*/ 
  34 // --------------------------------------------------------------------- 
  36 bool FileMethod::Fetch(FetchItem 
*Itm
) 
  39    string File 
= Get
.Path
; 
  41    if (Get
.Host
.empty() == false) 
  42       return _error
->Error(_("Invalid URI, local URIS must not start with //")); 
  44    // See if the file exists 
  46    if (stat(File
.c_str(),&Buf
) == 0) 
  48       Res
.Size 
= Buf
.st_size
; 
  50       Res
.LastModified 
= Buf
.st_mtime
; 
  52       if (Itm
->LastModified 
== Buf
.st_mtime 
&& Itm
->LastModified 
!= 0) 
  56    // See if we can compute a file without a .gz exentsion 
  57    string::size_type Pos 
= File
.rfind(".gz"); 
  58    if (Pos 
+ 3 == File
.length()) 
  60       File 
= string(File
,0,Pos
); 
  61       if (stat(File
.c_str(),&Buf
) == 0) 
  64          AltRes
.Size 
= Buf
.st_size
; 
  65          AltRes
.Filename 
= File
; 
  66          AltRes
.LastModified 
= Buf
.st_mtime
; 
  67          AltRes
.IMSHit 
= false; 
  68          if (Itm
->LastModified 
== Buf
.st_mtime 
&& Itm
->LastModified 
!= 0) 
  76    if (Res
.Filename
.empty() == true) 
  77       return _error
->Error(_("File not found")); 
  86    setlocale(LC_ALL
, "");