]>
git.saurik.com Git - apt.git/blob - apt-inst/dirstream.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: dirstream.cc,v 1.3.2.1 2004/01/16 18:58:50 mdz Exp $
4 /* ######################################################################
8 This class provides a simple basic extractor that can be used for
11 ##################################################################### */
13 // Include Files /*{{{*/
15 #pragma implementation "apt-pkg/dirstream.h"
18 #include <apt-pkg/dirstream.h>
19 #include <apt-pkg/error.h>
23 #include <sys/types.h>
30 // DirStream::DoItem - Process an item /*{{{*/
31 // ---------------------------------------------------------------------
32 /* This is a very simple extractor, it does not deal with things like
33 overwriting directories with files and so on. */
34 bool pkgDirStream::DoItem(Item
&Itm
,int &Fd
)
40 /* Open the output file, NDELAY is used to prevent this from
41 blowing up on device special files.. */
42 int iFd
= open(Itm
.Name
,O_NDELAY
|O_WRONLY
|O_CREAT
|O_TRUNC
|O_APPEND
,
45 return _error
->Errno("open",_("Failed write file %s"),
48 // fchmod deals with umask and fchown sets the ownership
49 if (fchmod(iFd
,Itm
.Mode
) != 0)
50 return _error
->Errno("fchmod",_("Failed write file %s"),
52 if (fchown(iFd
,Itm
.UID
,Itm
.GID
) != 0 && errno
!= EPERM
)
53 return _error
->Errno("fchown",_("Failed write file %s"),
60 case Item::SymbolicLink
:
61 case Item::CharDevice
:
62 case Item::BlockDevice
:
71 // DirStream::FinishedFile - Finished processing a file /*{{{*/
72 // ---------------------------------------------------------------------
74 bool pkgDirStream::FinishedFile(Item
&Itm
,int Fd
)
80 return _error
->Errno("close",_("Failed to close file %s"),Itm
.Name
);
82 /* Set the modification times. The only way it can fail is if someone
83 has futzed with our file, which is intolerable :> */
85 Time
.actime
= Itm
.MTime
;
86 Time
.modtime
= Itm
.MTime
;
87 if (utime(Itm
.Name
,&Time
) != 0)
88 _error
->Errno("utime",_("Failed to close file %s"),Itm
.Name
);
93 // DirStream::Fail - Failed processing a file /*{{{*/
94 // ---------------------------------------------------------------------
96 bool pkgDirStream::Fail(Item
&Itm
,int Fd
)