libzypp  13.10.6
MediaDIR.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
13 #include <iostream>
14 
15 #include "zypp/base/Logger.h"
16 #include "zypp/media/MediaDIR.h"
17 
18 #include <sys/mount.h>
19 #include <errno.h>
20 
21 using namespace std;
22 
23 namespace zypp {
24  namespace media {
25 
27  //
28  // CLASS NAME : MediaDIR
29  //
31 
33  //
34  //
35  // METHOD NAME : MediaDIR::MediaDIR
36  // METHOD TYPE : Constructor
37  //
38  // DESCRIPTION : Attach point is always url_r.getPathName(),
39  // as files are not copied.
40  // Thus attach_point_hint_r is ignored.
41  //
42  MediaDIR::MediaDIR( const Url & url_r,
43  const Pathname & /*attach_point_hint_r*/ )
44  : MediaHandler( url_r, url_r.getPathName(),
45  "/", // urlpath below attachpoint
46  false ) // does_download
47  {
48  MIL << "MediaDIR::MediaDIR(" << url_r << ")" << endl;
49  if( !url_r.getHost().empty())
50  {
52  "Hostname not allowed in the Url"
53  ));
54  }
55  }
56 
58  //
59  //
60  // METHOD NAME : MediaDIR::attachTo
61  // METHOD TYPE : PMError
62  //
63  // DESCRIPTION : Asserted that not already attached, and attachPoint is a directory.
64  //
65  void MediaDIR::attachTo(bool next)
66  {
67  if(next)
69 
70  // fetch attach point from url again if needed ...
71  // it may happen that attachPointHint (and attachPoint())
72  // does not contain any path, because the directory has
73  // not existed while the handler was constructed.
74  if( attachPoint().empty() && !url().getPathName().empty())
75  {
76  Pathname real( getRealPath(url().getPathName()));
77 
78  PathInfo adir( real);
79  if( adir.isDir())
80  {
81  // set attachpoint only if the dir exists
82  setAttachPoint( real, false);
83  }
84  else
85  {
87  "Specified path '" + url().getPathName() + "' is not a directory"
88  ));
89  }
90  }
91 
92  // attach point is same as source path... we do not mount here
93  if(attachPoint().empty())
94  {
96  "The media URL does not provide any useable directory path"
97  ));
98  }
99  else
100  if(!PathInfo(attachPoint()).isDir())
101  {
103  "Specified path '" + attachPoint().asString() + "' is not a directory"
104  ));
105  }
106 
107  MediaSourceRef media(new MediaSource("dir", attachPoint().asString()));
108  setMediaSource(media);
109  }
110 
111 
113  //
114  //
115  // METHOD NAME : MediaDIR::releaseFrom
116  // METHOD TYPE : void
117  //
118  // DESCRIPTION : Asserted that media is attached.
119  //
120  void MediaDIR::releaseFrom( const std::string & ejectDev )
121  {
122  return;
123  }
124 
126  //
127  //
128  // METHOD NAME : MediaDIR::getFile
129  // METHOD TYPE : PMError
130  //
131  // DESCRIPTION : Asserted that media is attached.
132  //
133  void MediaDIR::getFile( const Pathname & filename ) const
134  {
135  MediaHandler::getFile( filename );
136  }
137 
139  //
140  // METHOD NAME : MediaDIR::getDir
141  // METHOD TYPE : PMError
142  //
143  // DESCRIPTION : Asserted that media is attached.
144  //
145  void MediaDIR::getDir( const Pathname & dirname, bool recurse_r ) const
146  {
147  MediaHandler::getDir( dirname, recurse_r );
148  }
149 
151  //
152  //
153  // METHOD NAME : MediaDIR::getDirInfo
154  // METHOD TYPE : PMError
155  //
156  // DESCRIPTION : Asserted that media is attached and retlist is empty.
157  //
158  void MediaDIR::getDirInfo( std::list<std::string> & retlist,
159  const Pathname & dirname, bool dots ) const
160  {
161  MediaHandler::getDirInfo( retlist, dirname, dots );
162  }
163 
165  //
166  //
167  // METHOD NAME : MediaDIR::getDirInfo
168  // METHOD TYPE : PMError
169  //
170  // DESCRIPTION : Asserted that media is attached and retlist is empty.
171  //
173  const Pathname & dirname, bool dots ) const
174  {
175  MediaHandler::getDirInfo( retlist, dirname, dots );
176  }
177 
178  bool MediaDIR::getDoesFileExist( const Pathname & filename ) const
179  {
180  return MediaHandler::getDoesFileExist( filename );
181  }
182 
183  } // namespace media
184 } // namespace zypp
virtual void releaseFrom(const std::string &ejectDev)
Call concrete handler to release the media.
Definition: MediaDIR.cc:120
#define MIL
Definition: Logger.h:47
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:320
virtual void getDir(const Pathname &dirname, bool recurse_r) const =0
Call concrete handler to provide directory content (not recursive!) below attach point.
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
Definition: Url.cc:582
static std::string getRealPath(const std::string &path)
void setAttachPoint(const Pathname &path, bool temp)
Set a new attach point.
virtual void getDirInfo(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
Call concrete handler to provide a content list of directory on media via retlist.
Definition: MediaDIR.cc:158
virtual void getFile(const Pathname &filename) const
Call concrete handler to provide file below attach point.
Definition: MediaDIR.cc:133
Abstract base class for &#39;physical&#39; MediaHandler like MediaCD, etc.
Definition: MediaHandler.h:45
void setMediaSource(const MediaSourceRef &ref)
Set new media source reference.
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:544
virtual bool getDoesFileExist(const Pathname &filename) const
check if a file exists
Definition: MediaDIR.cc:178
std::string asString(const Patch::SeverityFlag &obj)
Definition: Patch.cc:149
Media source internally used by MediaManager and MediaHandler.
Definition: MediaSource.h:36
virtual void attachTo(bool next=false)
Call concrete handler to attach the media.
Definition: MediaDIR.cc:65
virtual void getDirInfo(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const =0
Call concrete handler to provide a content list of directory on media via retlist.
virtual bool getDoesFileExist(const Pathname &filename) const =0
check if a file exists
Pathname attachPoint() const
Return the currently used attach point.
virtual void getFile(const Pathname &filename) const =0
Call concrete handler to provide file below attach point.
virtual void getDir(const Pathname &dirname, bool recurse_r) const
Call concrete handler to provide directory content (not recursive!) below attach point.
Definition: MediaDIR.cc:145
Url url() const
Url used.
Definition: MediaHandler.h:506
Url manipulation class.
Definition: Url.h:87