]>
git.saurik.com Git - apt.git/blob - apt-inst/dirstream.cc
b62bdcae12457e0440ea3910093449218da5a7cc
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 /*{{{*/
16 #include <apt-pkg/dirstream.h>
17 #include <apt-pkg/error.h>
21 #include <sys/types.h>
27 // DirStream::DoItem - Process an item /*{{{*/
28 // ---------------------------------------------------------------------
29 /* This is a very simple extractor, it does not deal with things like
30 overwriting directories with files and so on. */
31 bool pkgDirStream::DoItem(Item
&Itm
,int &Fd
)
37 /* Open the output file, NDELAY is used to prevent this from
38 blowing up on device special files.. */
39 int iFd
= open(Itm
.Name
,O_NDELAY
|O_WRONLY
|O_CREAT
|O_TRUNC
|O_APPEND
,
42 return _error
->Errno("open",_("Failed to write file %s"),
45 // fchmod deals with umask and fchown sets the ownership
46 if (fchmod(iFd
,Itm
.Mode
) != 0)
49 return _error
->Errno("fchmod",_("Failed to write file %s"), Itm
.Name
);
51 if (fchown(iFd
,Itm
.UID
,Itm
.GID
) != 0 && errno
!= EPERM
)
54 return _error
->Errno("fchown",_("Failed to write file %s"), Itm
.Name
);
61 case Item::SymbolicLink
:
62 case Item::CharDevice
:
63 case Item::BlockDevice
:
67 // check if the dir is already there, if so return true
68 if (stat(Itm
.Name
,&Buf
) == 0)
70 if(S_ISDIR(Buf
.st_mode
))
72 // something else is there already, return false
75 // nothing here, create the dir
76 if(mkdir(Itm
.Name
,Itm
.Mode
) < 0)
88 // DirStream::FinishedFile - Finished processing a file /*{{{*/
89 // ---------------------------------------------------------------------
91 bool pkgDirStream::FinishedFile(Item
&Itm
,int Fd
)
96 /* Set the modification times. The only way it can fail is if someone
97 has futzed with our file, which is intolerable :> */
98 struct timespec times
[2];
99 times
[0].tv_sec
= times
[1].tv_sec
= Itm
.MTime
;
100 times
[0].tv_nsec
= times
[1].tv_nsec
= 0;
101 if (futimens(Fd
, times
) != 0)
102 _error
->Errno("futimens", "Failed to set modification time for %s",Itm
.Name
);
105 return _error
->Errno("close",_("Failed to close file %s"),Itm
.Name
);
109 // DirStream::Fail - Failed processing a file /*{{{*/
110 // ---------------------------------------------------------------------
112 bool pkgDirStream::Fail(Item
&Itm
,int Fd
)