Implement media doesFileExists().
[platform/upstream/libzypp.git] / zypp / media / MediaManager.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/media/MediaManager.h
10  *
11 */
12 #ifndef ZYPP_MEDIA_MEDIAMANAGER_H
13 #define ZYPP_MEDIA_MEDIAMANAGER_H
14
15 #include <zypp/media/MediaAccess.h>
16
17 #include <zypp/base/Deprecated.h>
18 #include <zypp/base/NonCopyable.h>
19 #include <zypp/base/PtrTypes.h>
20 #include <zypp/Pathname.h>
21 #include <zypp/Url.h>
22
23 #include <list>
24
25
26 //////////////////////////////////////////////////////////////////////
27 namespace zypp
28 { ////////////////////////////////////////////////////////////////////
29
30   ////////////////////////////////////////////////////////////////////
31   namespace media
32   { //////////////////////////////////////////////////////////////////
33
34
35     ///////////////////////////////////////////////////////////////////
36     typedef zypp::RW_pointer<MediaAccess> MediaAccessRef;
37
38     // OBSOLETE HERE:
39     typedef MediaAccessId                 MediaId;
40     typedef unsigned int                  MediaNr;
41
42
43     ///////////////////////////////////////////////////////////////////
44     // forward declaration
45     class MountEntry;
46     class MediaManager_Impl;
47
48     ///////////////////////////////////////////////////////////////////
49     //
50     // CLASS NAME : MediaVerifierBase
51     //
52     /**
53      * Interface to implement a media verifier.
54      */
55     class MediaVerifierBase //: private zypp::NonCopyable
56     {
57     public:
58       MediaVerifierBase()
59       {}
60
61       virtual
62       ~MediaVerifierBase()
63       {}
64
65       /**
66        * Returns a string with some info about the verifier.
67        * By default, the type info name is returned.
68        */
69       virtual std::string
70       info() const;
71
72       /*
73       ** Check if the specified attached media contains
74       ** the desired media (e.g. SLES10 CD1).
75       */
76       virtual bool
77       isDesiredMedia(const MediaAccessRef &ref) = 0;
78     };
79
80
81     ///////////////////////////////////////////////////////////////////
82     //
83     // CLASS NAME : NoVerifier
84     //
85     /**
86      * Dummy default media verifier, which is always happy.
87      */
88     class NoVerifier : public MediaVerifierBase
89     {
90     public:
91       NoVerifier(): MediaVerifierBase()
92       {}
93
94       virtual
95       ~NoVerifier()
96       {}
97
98       /**
99        * Returns the "zypp::media::NoVerifier" string.
100        */
101       virtual std::string
102       info() const;
103
104       /*
105       ** Don't check if the specified attached media contains
106       ** the desired media number. Always return true.
107       */
108       virtual bool
109       isDesiredMedia(const MediaAccessRef &ref)
110       {
111         (void)ref;
112         return true;
113       }
114     };
115
116
117     ///////////////////////////////////////////////////////////////////
118     //
119     // CLASS NAME : MediaVerifierRef
120     //
121     /**
122      * A shared reference to the MediaVerifier implementation.
123      */
124     typedef zypp::RW_pointer<MediaVerifierBase> MediaVerifierRef;
125
126
127     ///////////////////////////////////////////////////////////////////
128     //
129     // CLASS NAME : MediaManager
130     //
131     /**
132      * Manages access to the 'physical' media, e.g CDROM drives,
133      * Disk volumes, directory trees, etc, using \ref MediaAccessUrl's.
134      *
135      * \note The MediaManager class is just an envelope around an
136      *       inner singleton like implementation.<br>
137      *       That is, you can create as many managers as you want,
138      *       also temporary in a function call.<br>
139      *       But <b>don't</b> declare static MediaManager instances,
140      *       unless you want to force (mutex) initialization order
141      *       problems!
142      *
143      * \section MediaAccessUrl Media Access Url
144      * The MediaManager uses several media access handlers (backends),
145      * that can be specified by a Media Access URL in its open() method.
146      *
147      * All URL's may contain following query parameters, that are
148      * reserved by the Source classes and unused/ignored by the media
149      * manager:
150      * - <tt>alias</tt>: A source specific media alias string.
151      *
152      * Currently, following access handlers (backends) are implemented:
153      *   - \ref MediaCD_Url
154      *   - \ref MediaDISK_Url
155      * .
156      *   - \ref MediaISO_Url
157      *   - \ref MediaDIR_Url
158      * .
159      *   - \ref MediaNFS_Url
160      *   - \ref MediaCIFS_Url
161      *   - \ref MediaCurl_Url
162      *
163      * \subsection MediaCD_Url MediaCD - CD/DVD drives (cd, dvd)
164      * The access handler for media on CD / DVD drives.
165      *   - Scheme:
166      *     - <b>cd</b>: Requires a drive supporting CD media.
167      *     - <b>dvd</b>: Prefers a drive supporting DVD media.
168      *   - Examples:
169      *     \code
170      *       "cd:/"
171      *       "cd:/?devices=/dev/hda,/dev/hdb"
172      *       "cd:/subdir?devices=/dev/hda,/dev/hdb"
173      *
174      *       "dvd:/"
175      *       "dvd:/?devices=/dev/hda,/dev/hdb"
176      *       "dvd:/subdir?devices=/dev/hda,/dev/hdb"
177      *     \endcode
178      *     Note: You can use either "dvd:/" (just path, no authority)
179      *           or "dvd:///" (path and empty authority).
180      *   - Query parameters:
181      *     - <tt>devices</tt>:
182      *       Optional parameter, containing a comma separated list of
183      *       block device names to use, e.g.: "/dev/sr0,/dev/sr1".
184      *       <br>
185      *       The device names will be verified using a HAL query. If one
186      *       of the provided devices is not usable (not a block device,
187      *       or does not support required media type), an exception is
188      *       thrown.
189      *       <br>
190      *       If the devices parameter is not provided (or empty), all
191      *       avaliable CD/DVD drives 'detected' using a HAL query. The
192      *       preferred drive (used as first drive) is the drive pointed
193      *       to by the symlink "/dev/dvd" ("dvd" scheme only) or
194      *       "/dev/cdrom".
195      *   - Authority:
196      *     A non-empty authority URL component (e.g. containing a host
197      *     name) is not allowed.
198      *   - Path name:
199      *     Mandatory URL component, that specifies a subdirectory on the
200      *     CD/DVD, where the desired files are located.
201      *
202      * \subsection MediaDISK_Url MediaDISK - HD disk volumes (hd)
203      * The access handler for media on a disk volume (partition).
204      *   - Scheme:
205      *     - <b>hd</b>
206      *   - Examples:
207      *     \code
208      *       "hd:/?device=/dev/hda1"
209      *       "hd:/subdir?device=/dev/sda1"
210      *       "hd:/subdir?device=/dev/sda1&filesystem=reiserfs"
211      *     \endcode
212      *     Note: You can use either "hd:/" (just path, no authority)
213      *     or "hd:///" (path and empty authority).
214      *   - Query parameters:
215      *     - <tt>device</tt>:
216      *       Mandatory parameter specifying the name of the block device of
217      *       the partition to mount.
218      *     - <tt>filesystem</tt>:
219      *       The name of the filesystem. Defaults to "auto". 
220      *   - Authority:
221      *     A non-empty authority URL component is not allowed.
222      *   - Path name:
223      *     Mandatory URL component, that specifies a subdirectory on the disk
224      *     partition, where the desired files are located.
225      *
226      * \subsection MediaDIR_Url MediaDIR - Local directory tree (dir, file)
227      * The access handler to media stored in a local directory tree.
228      *   - Scheme:
229      *     - <b>dir</b>
230      *     - <b>file</b>
231      *   - Examples:
232      *     \code
233      *       "dir:/directory/name"
234      *       "file:/directory/name"
235      *     \endcode
236      *   - Query parameters:
237      *     none 
238      *   - Authority:
239      *     A non-empty authority URL component (e.g. containing
240      *     a host name) is not allowed.
241      *   - Path name:
242      *     Mandatory URL component, that specifies a directory, where
243      *     the desired files are located.
244      *
245      * \subsection MediaISO_Url MediaISO - Loopback ISO images (iso)
246      * The access handler for media in a ISO image (loopback mount).
247      *   - Scheme:
248      *     - <b>iso</b>
249      *   - Examples:
250      *     \code
251      *       "iso:/?iso=/path/to/CD1.iso"
252      *       "iso:/?iso=CD1.iso&url=dir:/path/to"
253      *
254      *       "iso:/?iso=CD1.iso&url=nfs://server/path/to/media"
255      *       "iso:/?iso=CD1.iso&url=hd:/?device=/dev/hda"
256      * 
257      *        "iso:/subdir?iso=DVD1.iso&url=nfs://nfs-server/directory&mnt=/nfs/attach/point&filesystem=udf"
258      *     \endcode
259      *   - Query parameters:
260      *     - <tt>iso</tt>:
261      *       Mandatory parameter specifying the name of the iso file.<br>
262      *       If the url parameter is missed, the iso parameter has to contain
263      *       an absolute iso file name.
264      *     - <tt>url</tt>:
265      *       Optional parameter specifying the URL to the directory containing
266      *       the iso file.<br>
267      *       The supported URL schemes are: <i><b>hd</b>, <b>dir</b>,
268      *       <b>file</b>, <b>nfs</b>, <b>smb</b>, <b>cifs</b>.</i>
269      *     - <tt>mnt</tt>:
270      *       Optional parameter specifying the prefered attach point for the
271      *       source media url.
272      *     - <tt>filesystem</tt>:
273      *       Optional name of the filesystem used in the iso file. Defaults
274      *       to "auto". 
275      *   - Authority:
276      *     A non-empty authority URL component is not allowed.
277      *   - Path name:
278      *     Mandatory URL component, that specifies a subdirectory inside of
279      *     the iso file, where the desired files are located.
280      *
281      * \subsection MediaNFS_Url MediaNFS  - NFS directory tree (nfs)
282      * The access handler for media on NFS exported directory tree.
283      *   - Scheme:
284      *     - <b>nfs</b>
285      *   - Examples:
286      *     \code
287      *        "nfs://nfs-server/exported/path"
288      *        "nfs://nfs-server/exported/path?mountoptions=ro"
289      *     \endcode
290      *   - Query parameters:
291      *     - <tt>mountoptions</tt>:
292      *       The mount options separated by comma ','.
293      *       Default is the "ro" option.
294      *   - Authority:
295      *     The authority component has to provide a hostname.
296      *     Username, password and port are currently ignored.
297      *   - Path name:
298      *     Mandatory URL component, that specifies the exported
299      *     (sub-)directory on the NFS server, where the desired
300      *     files are located.
301      *
302      * \subsection MediaCIFS_Url MediaCIFS - CIFS/SMB directory tree (cifs, smb)
303      * The access handler for media in a CIFS/SMB shared directory tree.
304      *   - Scheme:
305      *     - <b>cifs</b>
306      *     - <b>smb</b>
307      *   - Examples:
308      *     \code
309      *       "cifs://servername/share/path/on/the/share"
310      *       "cifs://username:passwd@servername/share/path/on/the/share?mountoptions=ro"
311      *       "smb://servername/share/path/on/the/share"
312      *       "smb://username:passwd@servername/share/path/on/the/share?mountoptions=ro"
313      *     \endcode
314      *     Note: There is no difference between cifs and smb scheme
315      *     (any more). In both cases the 'cifs' filesystem is used.
316      *   - Query parameters:
317      *     - <tt>mountoptions</tt>:
318      *       The mount options separated by a comma ','. Default are the
319      *       "ro" and "guest" options.
320      *     - <tt>workgroup</tt>:
321      *       The name of the workgroup.
322      *     - <tt>username</tt>:
323      *       Alternative username to username in URL authority.
324      *     - <tt>password</tt>:
325      *       Alternative password to password in URL authority.
326      *     - <tt>user</tt>:
327      *       Alternative username (cifs specific variant?)
328      *     - <tt>pass</tt>:
329      *       Alternative password (cifs specific variant?)
330      *   - Authority:
331      *     The authority component has to provide a hostname. Optionally
332      *     also a username and password.
333      *   - Path name:
334      *     Mandatory URL component, that specifies the share name with
335      *     optional subdirectory, where the desired files are located.
336      *
337      * \subsection MediaCurl_Url MediaCurl - FTP/HTTP directory tree (ftp, http, https) 
338      * The access handler to media directory tree on a ftp/http server.
339      *   - Scheme:
340      *     - <b>ftp</b>
341      *     - <b>http</b>
342      *     - <b>https</b>
343      *   - Examples:
344      *     \code
345      *       "ftp://server/relative/path/to/media/dir"
346      *       "ftp://server/%2fabsolute/path/to/media/dir"
347      *
348      *       "ftp://user:pass@server/path/to/media/dir"
349      *       "ftp://user:pass@server/%2f/home/user/path/to/media/dir"
350      *
351      *       "http://server/path/on/server"
352      *       "http://user:pass@server/path"
353      *       "https://user:pass@server/path?proxy=foo&proxyuser=me&proxypass=pw"
354      *     \endcode
355      *     Note: The "ftp" url scheme supports absolute and relative
356      *     paths to the default ftp server directory
357      *     (<a href="http://rfc.net/rfc1738.html">RFC1738, Section 3.2.2</a>).<br>
358      *     To use an absolute path, you have to prepend the path with an
359      *     additional slash, what results in a "/%2f" combination
360      *     (second "/" encoded to "%2f") at the begin of the URL path.
361      *     <br>
362      *     This is important, especially in user authenticated ftp,
363      *     where the users home is usually the default directory of the
364      *     server (except when the server chroots into the users home
365      *     directory).
366      *     <br>
367      *     For example, if the user "user" has a home directory
368      *     "/home/user", you can use either an URL with a relative path
369      *     to the home directory "ftp://user:pass@server/path/to/media"
370      *     or the absolute path
371      *     "ftp://user:pass@server/%2fhome/user/path/to/media" -- both
372      *     URLs points to the same directory on the server.
373      *   - Query parameters:
374      *     - <tt>proxy</tt>:
375      *       A proxy hostname or hostname and port separated by ':'.
376      *     - <tt>proxyport</tt>:
377      *       Alternative way to provide the proxy port.
378      *     - <tt>proxyuser</tt>:
379      *       The proxy username.
380      *     - <tt>proxypass</tt>:
381      *       The proxy password.
382      *     - <tt>ssl_capath</tt>:
383      *       The absolute CA directory to use, default is /etc/ssl/certs.
384      *     - <tt>ssl_verify</tt>: Flag to modify the ssl verify behaviour.
385      *       Valid values are: 'yes', 'no' and a comma separated list of
386      *       'host' and 'peer' flags.
387      *       - 'no':
388      *         disables ssl verify
389      *       - 'yes':
390      *         enables ssl verify, this is the default
391      *         and is equivalent to 'host,peer'.
392      *       - 'host': The server is considered the intended one, when the
393      *         'Common Name' field or a 'Subject Alternate Name' field in 
394      *         the certificate matches the host name in the URL.
395      *       - 'peer': Verifies whether the certificate provided by the
396      *         server is authentic against the chain of digital signatures
397      *         found in <tt>ssl_capath</tt>. 
398      *     - <tt>timeout</tt>:
399      *       Transfer timeout in seconds between 0 and 3600, 0 disables
400      *       the timeout, default timeout is 180 seconds.
401      *     - <tt>auth</tt>: A comma separated list of http authentication
402      *       method names to use: 'basic', 'digest', 'ntlm', 'negotiate',
403      *       'spnego', 'gssnego'.
404      *       Note, that this list depends on the list of methods supported
405      *       by the curl library. 
406      *   - Authority:
407      *     The authority component has to provide a hostname. Optionally
408      *     also a username and password. In case of the 'ftp' scheme,
409      *     username and password defaults to 'anonymous' and 'yast2@'.
410      *   - Path name:
411      *     Mandatory URL component, that specifies the path name on the
412      *     server, where the desired files are located.
413      *
414      *   Proxy settings: If no proxy settings are present in tha URLs
415      *   query parameters, the media handler reads the system wide proxy
416      *   settings from the <tt>/etc/sysconfig/proxy</tt> file.
417      *   If a proxy setting was present, but the proxy password not,
418      *   it attempts to read the <tt>proxy-user</tt> variable from the
419      *   <tt>~/.curlrc</tt> (<tt>/root/.curlrc</tt>) file.
420      *   <br>
421      *   If no proxy setting was present, then libzypp does not pass any
422      *   proxy settings to curl, but curl fallbacks to use the content of
423      *   the <tt>http_proxy</tt>, <tt>ftp_proxy</tt>, etc environment
424      *   variables.
425      */
426     class MediaManager: private zypp::base::NonCopyable
427     {
428     public:
429       /**
430        * Creates a MediaManager envelope instance.
431        *
432        * In the case, that the inner implementation is not already
433        * allocated, and the MediaManager constructor was unable to
434        * allocate it, a std::bad_alloc exception is thrown.
435        *
436        * All further instances increase the use counter only.
437        *
438        * \throws std::bad_alloc
439        */
440       MediaManager();
441
442       /**
443        * Destroys MediaManager envelope instance.
444        * Decreases the use counter of the inner implementation.
445        */
446       ~MediaManager();
447
448       /**
449        * Opens the media access for specified with the url.
450        *
451        * If the \p preferred_attach_point parameter does not
452        * point to a usable attach point directory, the media
453        * manager automatically creates a temporary attach
454        * point in a default directory. This default directory
455        * can be changed using setAttachPrefix() function.
456        *
457        * Remember to close() each id you've opened and not
458        * need any more. It is like a new and delete!
459        *
460        * \param  url The \ref MediaAccessUrl.
461        * \param  preferred_attach_point The preferred, already
462        *         existing directory, where the media should be
463        *         attached.
464        * \return a new media access id.
465        * \throws std::bad_alloc
466        * \throws MediaException
467        */
468       MediaAccessId
469       open(const Url &url, const Pathname & preferred_attach_point = "");
470
471       /**
472        * Close the media access with specified id.
473        * \param accessId The media access id to close.
474        */
475       void
476       close(MediaAccessId accessId);
477
478       /**
479        * Query if the media access is open / exists.
480        *
481        * \param accessId The media access id to query.
482        * \return true, if access id is known and open.
483        */
484       bool
485       isOpen(MediaAccessId accessId) const;
486
487       /**
488        * Query the protocol name used by the media access
489        * handler. Similar to url().getScheme().
490        *
491        * \param accessId The media access id to query.
492        * \return The protocol name used by the media access
493        *         handler, otherwise 'unknown'.
494        * \throws MediaNotOpenException for invalid access id.
495        */
496       std::string
497       protocol(MediaAccessId accessId) const;
498
499       /**
500        * Hint if files are downloaded or not.
501        * \param accessId The media access id to query.
502        * \return True, if provideFile downloads files.
503        */
504       bool
505       downloads(MediaAccessId accessId) const;
506
507       /**
508        * Hint if files will be downloaded when using the
509        * specified media \p url.
510        *
511        * @note This hint is based on the \p url scheme
512        * only and does not imply, that the URL is valid.
513        *
514        * @param url The media URL to check.
515        * @return True, if the files are downloaded.
516        */
517       static bool
518       downloads(const Url &url);
519
520       /**
521        * Returns the \ref MediaAccessUrl of the media access id.
522        *
523        * \param accessId The media access id to query.
524        * \return The \ref MediaAccessUrl used by the media access id.
525        * \throws MediaNotOpenException for invalid access id.
526        */
527       Url
528       url(MediaAccessId accessId) const;
529
530     public:
531       /**
532        * Add verifier implementation for the specified media id.
533        * By default, the NoVerifier is used.
534        *
535        * \param accessId A media access id.
536        * \param verifier The new verifier.
537        * \throws MediaNotOpenException for invalid access id.
538        */
539       void
540       addVerifier(MediaAccessId accessId,
541                   const MediaVerifierRef &verifier);
542
543       /**
544        * Remove verifier for specified media id.
545        * It resets the verifier to NoVerifier.
546        *
547        * \param accessId A media access id.
548        * \throws MediaNotOpenException for invalid access id.
549        */
550       void
551       delVerifier(MediaAccessId accessId);
552
553     public:
554       /**
555        * Set or resets the directory name, where the media manager
556        * handlers create their temporary attach points (see open()
557        * function).
558        * It has effect to newly created temporary attach points only.
559        *
560        * \param attach_prefix The new prefix for temporary attach
561        *        points, or empty pathname to reset to defaults.
562        * \return True on success, false if the \p attach_prefix
563        *         parameters contains a path name, that does not
564        *         point to a writable directory.
565        */
566       bool
567       setAttachPrefix(const Pathname &attach_prefix);
568
569       /**
570        * Attach the media using the concrete handler.
571        *
572        * Remember to release() or close() each id you've attached
573        * and not need any more. Attach is like an open of a file!
574        *
575        * \param accessId A media access id.
576        * \param next     Whether to try the next drive if avaliable.
577        * \throws MediaNotOpenException for invalid access id.
578        */
579       void
580       attach(MediaAccessId accessId, bool next = false);
581
582       /**
583        * Release the attached media and optionally eject.
584        *
585        * If the \p eject parameter is set to true and there
586        * is currently an attached drive, all other access
587        * id's are released and the drive (CD/DVD drive) is
588        * ejected.
589        * In case that there is currently no attached drive,
590        * a \p eject set to true causes to eject all drives
591        * that are _not_ used by another access id's.
592        *
593        * \param accessId A media access id.
594        * \param eject    Whether to eject the drive.
595        * \throws MediaNotOpenException for invalid access id.
596        */
597       void
598       release(MediaAccessId accessId, bool eject = false);
599
600       /**
601        * Disconnect a remote media.
602        *
603        * This is useful for media which e.g. holds open a connection
604        * to a server like FTP. After calling disconnect() the media
605        * object (attach point) is still valid and files are present.
606        *
607        * But after calling disconnect() it's not possible to call
608        * fetch more data using the provideFile() or provideDir()
609        * functions anymore.
610        *
611        * \param accessId A media access id.
612        * \throws MediaNotOpenException for invalid access id.
613        */
614       void
615       disconnect(MediaAccessId accessId);
616
617       /**
618        * Check if media is attached or not.
619        *
620        * \param accessId A media access id.
621        * \return True if media is attached.
622        * \throws MediaNotOpenException for invalid access id.
623        */
624       bool
625       isAttached(MediaAccessId accessId) const;
626
627       /**
628        * Returns information if media is on a shared
629        * physical device or not.
630        *
631        * \param accessId A media access id.
632        * \return True if it is shared, false if not.
633        * \throws MediaNotOpenException for invalid access id.
634        */
635       bool
636       isSharedMedia(MediaAccessId accessId) const;
637
638       /**
639        * Ask the registered verifier if the attached
640        * media is the desired one or not.
641        *
642        * \param accessId A media access id.
643        * \return True if media is attached and desired
644        *         according to the actual verifier.
645        * \throws MediaNotOpenException for invalid access id.
646        */
647       bool
648       isDesiredMedia(MediaAccessId accessId) const;
649
650       /**
651        * Ask the specified verifier if the attached
652        * media is the desired one or not.
653        *
654        * \param accessId A media access id.
655        * \param verifier A verifier to use.
656        * \return True if media is attached and desired
657        *         according to the specified verifier.
658        * \throws MediaNotOpenException for invalid access id.
659        */
660       bool
661       isDesiredMedia(MediaAccessId           accessId,
662                      const MediaVerifierRef &verifier) const;
663
664       /**
665        * Return the local directory that corresponds to medias url,
666        * no matter if media isAttached or not. Files requested will
667        * be available at 'localRoot() + filename' or even better
668        * 'localPath( filename )'
669        *
670        * \param accessId A media access id.
671        * \returns The directory name pointing to the media root
672        *          in local filesystem or an empty pathname if the
673        *          media is not attached.
674        * \throws MediaNotOpenException for invalid access id.
675        */
676       Pathname
677       localRoot(MediaAccessId accessId) const;
678
679       /**
680        * Shortcut for 'localRoot() + pathname', but returns an empty
681        * pathname if media is not attached.
682        * Files provided will be available at 'localPath(filename)'.
683        *
684        * \param accessId A media access id.
685        * \param pathname A path name relative to the localRoot().
686        * \returns The directory name in local filesystem pointing
687        *          to the desired relative pathname on the media
688        *          or an empty pathname if the media is not attached.
689        * \throws MediaNotOpenException for invalid access id.
690        */
691       Pathname
692       localPath(MediaAccessId accessId, const Pathname & pathname) const;
693
694     public:
695       /**
696        * Provide provide file denoted by relative path below of the
697        * 'attach point' of the specified media and the path prefix
698        * on the media.
699        *
700        * \param accessId  The media access id to use.
701        * \param filename  The filename to provide, relative to localRoot().
702        * \param cached    If cached is set to true, the function checks, if
703        *                  the file already exists and doesn't download it again
704        *                  if it does. Currently only the existence is checked,
705        *                  no other file attributes.
706        * \param checkonly If this and 'cached' are set to true only the
707        *                  existence of the file is checked but it's not
708        *                  downloaded. If 'cached' is unset an errer is
709        *                  returned always.
710        *
711        * \throws MediaNotOpenException in case of invalid access id.
712        * \throws MediaNotAttachedException in case, that the media is not attached.
713        * \throws MediaNotDesiredException in case, that the media verification failed.
714        * \throws MediaNotAFileException in case, that the requested filename is not a file.
715        * \throws MediaFileNotFoundException in case, that the requested filenamedoes not exists.
716        * \throws MediaWriteException in case, that the file can't be copied from from remote source.
717        * \throws MediaSystemException in case a system operation fails.
718        * \throws MediaException derived exception, depending on the url (handler).
719        */
720       void
721       provideFile(MediaAccessId   accessId,
722                   const Pathname &filename,
723                   bool            cached    = false,
724                   bool            checkonly = false) const;
725
726       /**
727        * FIXME: see MediaAccess class.
728        */
729       void
730       provideDir(MediaAccessId   accessId,
731                  const Pathname &dirname) const;
732
733       /**
734        * FIXME: see MediaAccess class.
735        */
736       void
737       provideDirTree(MediaAccessId  accessId,
738                      const Pathname &dirname) const;
739
740       /**
741        * FIXME: see MediaAccess class.
742        */
743       void
744       releaseFile(MediaAccessId   accessId,
745                   const Pathname &filename) const;
746
747       /**
748        * FIXME: see MediaAccess class.
749        */
750       void
751       releaseDir(MediaAccessId   accessId,
752                  const Pathname &dirname) const;
753
754       /**
755        * FIXME: see MediaAccess class.
756        */
757       void
758       releasePath(MediaAccessId   accessId,
759                   const Pathname &pathname) const;
760
761       /**
762        * FIXME: see MediaAccess class.
763        */
764       void
765       dirInfo(MediaAccessId           accessId,
766               std::list<std::string> &retlist,
767               const Pathname         &dirname,
768               bool                    dots = true) const;
769
770       /**
771        * FIXME: see MediaAccess class.
772        */
773       void
774       dirInfo(MediaAccessId           accessId,
775               filesystem::DirContent &retlist,
776               const Pathname         &dirname,
777               bool                   dots = true) const;
778
779       /**
780        * FIXME: see MediaAccess class.
781        */
782       bool doesFileExist(MediaAccessId  accessId,
783                          const Pathname & filename ) const;
784     public:
785       /**
786        * Get the modification time of the /etc/mtab file.
787        * \return Modification time of the /etc/mtab file.
788        */
789       static time_t
790       getMountTableMTime();
791
792       /**
793        * Get current mount entries from /etc/mtab file.
794        * \return Current mount entries from /etc/mtab file.
795        */
796       static std::vector<MountEntry>
797       getMountEntries();
798
799       /**
800        * Check if the specified \p path is useable as
801        * attach point.
802        *
803        * \param path The attach point to check.
804        * \param mtab Whether to check against the mtab, too.
805        * \return True, if it is a directory and there are
806        *         no another attach points bellow of it.
807        */
808       bool
809       isUseableAttachPoint(const Pathname &path,
810                            bool            mtab=true) const;
811
812     private:
813       friend class MediaHandler;
814
815       /**
816        * \internal
817        * Return the attached media reference of the specified
818        * media access id. Used to resolve nested attachments
819        * as used in the MediaISO (iso-loop) handler.
820        * Causes temporary creation of a shared attachment
821        * (increases reference counters on attachedMedia).
822        * \param media A media access id.
823        */
824       AttachedMedia
825       getAttachedMedia(MediaAccessId &accessId) const;
826
827       /**
828        * \internal
829        * Called by media handler in while attach() to retrieve
830        * attached media reference matching the specified media
831        * source reference.
832        * Causes temporary creation of a shared attachment
833        * (increases reference counters on attachedMedia).
834        * \param media The media source reference to search for.
835        */
836       AttachedMedia
837       findAttachedMedia(const MediaSourceRef &media) const;
838
839       /**
840        * \internal
841        * Called by media handler in case of relase(eject=true)
842        * to release all access id's using the specified media.
843        * Causes temporary creation of a shared attachment
844        * (increases reference counters on attachedMedia).
845        * \param media The media source reference to release.
846        */
847       void
848       forceReleaseShared(const MediaSourceRef &media);
849
850     private:
851       /**
852        * Static reference to the implementation (singleton).
853        */
854       static zypp::RW_pointer<MediaManager_Impl> m_impl;
855     };
856
857
858     //////////////////////////////////////////////////////////////////
859   } // namespace media
860   ////////////////////////////////////////////////////////////////////
861
862   ////////////////////////////////////////////////////////////////////
863 } // namespace zypp
864 //////////////////////////////////////////////////////////////////////
865
866 #endif // ZYPP_MEDIA_MEDIAMANAGER_H
867
868 /*
869 ** vim: set ts=2 sts=2 sw=2 ai et:
870 */