1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/media/MediaManager.h
12 #ifndef ZYPP_MEDIA_MEDIAMANAGER_H
13 #define ZYPP_MEDIA_MEDIAMANAGER_H
15 #include <zypp/media/MediaAccess.h>
17 #include <zypp/base/Deprecated.h>
18 #include <zypp/base/NonCopyable.h>
19 #include <zypp/base/PtrTypes.h>
20 #include <zypp/Pathname.h>
26 //////////////////////////////////////////////////////////////////////
28 { ////////////////////////////////////////////////////////////////////
30 ////////////////////////////////////////////////////////////////////
32 { //////////////////////////////////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////
36 typedef zypp::RW_pointer<MediaAccess> MediaAccessRef;
39 typedef MediaAccessId MediaId;
40 typedef unsigned int MediaNr;
43 ///////////////////////////////////////////////////////////////////
44 // forward declaration
48 ///////////////////////////////////////////////////////////////////
50 // CLASS NAME : MediaVerifierBase
53 * Interface to implement a media verifier.
55 class MediaVerifierBase //: private zypp::NonCopyable
66 ** Check if the specified attached media contains
67 ** the desired media (e.g. SLES10 CD1).
70 isDesiredMedia(const MediaAccessRef &ref) = 0;
74 ///////////////////////////////////////////////////////////////////
76 // CLASS NAME : NoVerifier
79 * Dummy default media verifier, which is always happy.
81 class NoVerifier : public MediaVerifierBase
84 NoVerifier(): MediaVerifierBase()
92 ** Don't check if the specified attached media contains
93 ** the desired media number. Always return true.
96 isDesiredMedia(const MediaAccessRef &ref)
104 ///////////////////////////////////////////////////////////////////
106 // CLASS NAME : MediaVerifierRef
109 * A shared reference to the MediaVerifier implementation.
111 typedef zypp::RW_pointer<MediaVerifierBase> MediaVerifierRef;
114 ///////////////////////////////////////////////////////////////////
116 // CLASS NAME : MediaManager
119 * Manages coordinated access to 'physical' media, e.g CDROM
120 * drives using \ref MediaAccessUrl's.
122 * \note The MediaManager class is just an envelope around an
123 * inner singelton like implementation.
125 * This means, you can create as many managers as you want,
126 * also temporary in a function call.
128 * Don't declare static MediaManager instances, unless
129 * you want to force (mutex) initialization order problems!
131 * \section MediaAccessUrl Media Access Url
132 * The Media Manager currently supports following access handlers
133 * (backends), that can be specified by the media access URLs in
134 * the media manager's open() method.
137 * Supports multiple CD or DVD drives.
141 * "cd:/?devices=/dev/hda,/dev/hdb"
142 * "cd:/subdir?devices=/dev/hda,/dev/hdb"
144 * "dvd:/?devices=/dev/hda,/dev/hdb"
145 * "dvd:/subdir?devices=/dev/hda,/dev/hdb"
148 * - <b>cd</b>: Requires a drive supporting CD media.
149 * - <b>dvd</b>: Requires a drive supporting DVD media.
151 * A non-empty authority URL component (e.g. containing a host
152 * name) is not allowed.
154 * Specifies a subdirectory on the CD/DVD, where the desired files
155 * are located. In case of "/", the CD/DVD's root directory (the
156 * mount point) is used.
157 * - Query parameters:
158 * - <tt>devices</tt>:
159 * Optional parameter, containing a comma separated list of block
160 * device names to use.
162 * The device names will be verified using a HAL query. If one of
163 * the provided devices is not usable (not a block device, or does
164 * not support required media type), exception is thrown.
166 * If the devices parameter is not provided (or empty), all
167 * avaliable CD/DVD drives 'detected' using a HAL query. The
168 * preferred drive (used as first drive) is the drive pointed to
169 * by the symlink "/dev/dvd" ("dvd" scheme only) or "/dev/cdrom".
174 * "nfs://nfs-server/exported/path"
175 * "nfs://nfs-server/exported/path?mountoptions=ro"
180 * The authority component has to provide a hostname.
181 * Username, password and port are currently ignored.
183 * Exported (sub-)directory on the NFS server where the desired
185 * - Query parameters:
186 * - <tt>mountoptions</tt>:
187 * The mount options separated by comma ','.
188 * Default is the "ro" option.
190 * - MediaCIFS (MediaSMB):
193 * "cifs://servername/share/path/on/the/share"
194 * "cifs://username:passwd@servername/share/path/on/the/share?mountoptions=ro"
195 * "smb://servername/share/path/on/the/share"
196 * "smb://username:passwd@servername/share/path/on/the/share?mountoptions=ro"
200 * - <b>smb</b>: Just an alias for 'cifs'.
202 * The authority component has to provide a hostname. Optionally
203 * also a username and password.
205 * The share name with optional subdirectory where the desired
207 * - Query parameters:
208 * - <tt>mountoptions</tt>:
209 * The mount options separated by a comma ','. Default are the
210 * "ro" and "guest" options.
211 * - <tt>workgroup</tt>:
212 * The name of the workgroup.
213 * - <tt>username</tt>:
214 * Alternative username to username in URL authority.
215 * - <tt>password</tt>:
216 * Alternative password to password in URL authority.
218 * Alternative username (cifs specific variant?)
220 * Alternative password (cifs specific variant?)
225 * "ftp://server/path/on/server"
226 * "http://server/path/on/server"
227 * "https://server/path/on/server"
228 * "http://user:pass@server/path"
229 * "http://user:pass@server/path?proxy=foo&proxyuser=me&proxypass=pw"
236 * The authority component has to provide a hostname. Optionally
237 * also a username and password. In case of the 'ftp' scheme,
238 * username and password defaults to 'anonymous' and 'yast2@'.
240 * The path name on the server where the desired files are located.
241 * - Query parameters:
243 * A proxy hostname or hostname and port separated by ':'.
244 * - <tt>proxyport</tt>:
245 * Alternative way to provide the proxy port.
246 * - <tt>proxyuser</tt>:
247 * The proxy username.
248 * - <tt>proxypass</tt>:
249 * The proxy password.
254 * "dir:/directory/name"
255 * "file:/directory/name"
261 * A non-empty authority URL component (e.g. containing
262 * a host name) is not allowed.
264 * Specifies a directory, where the desired files are located.
265 * - Query parameters:
271 * "hd:/?device=/dev/hda1"
272 * "hd:/subdir?device=/dev/sda1"
273 * "hd:/subdir?device=/dev/sda1&filesystem=reiserfs"
278 * A non-empty authority URL component is not allowed.
280 * Specifies a subdirectory on the disk partition, where the desired
281 * files are located. In case of "/", the partition's root directory
282 * (its mount point) is used.
283 * - Query parameters:
285 * Mandatory parameter specifying the name of the block device of
286 * the partition to mount.
287 * - <tt>filesystem</tt>:
288 * The name of the filesystem. Defaults to "auto".
293 * "iso:/?iso=/local/directory/filename.iso"
294 * "iso:/?iso=filename.iso&url=nfs://nfs-server/exported/directory"
295 * "iso:/isoSubdir?iso=urlSubdir/filename.iso&filesystem=iso9660&mnt=/urlAttachPoint&url=nfs://nfs-server/directory"
300 * A non-empty authority URL component is not allowed.
302 * Specifies a subdirectory inside of the iso file, where the desired
303 * files are located. In case of "/", the iso files's root directory
304 * (its mount point) is used.
305 * - Query parameters:
307 * Mandatory parameter specifying the name of the iso file.
308 * - If the url parameter is present, the filename can contain a
309 * relative path to the iso file below of the location pointed by
311 * - If the url parameter is missed, the iso parameter has to point
312 * to the absolute iso file name.
314 * Optional parameter specifying the iso filename's source media url
315 * pointing to a directory.
317 * Note: <i>The iso filename's source media url schemes are limited
318 * to: <b>hd</b>, <b>dir</b>, <b>file</b>,
319 * <b>nfs</b>, <b>smb</b>, <b>cifs</b>.</i>
321 * Optional parameter specifying the prefered attach point for the
323 * - <tt>filesystem</tt>:
324 * Optional name of the filesystem used in the iso file. Defaults
327 class MediaManager: private zypp::base::NonCopyable
331 * Creates a MediaManager envelope instance.
333 * In the case, that the inner implementation is not already
334 * allocated, and the MediaManager constructor was unable to
335 * allocate it, a std::bad_alloc exception is thrown.
337 * All further instances increase the use counter only.
339 * \throws std::bad_alloc
344 * Destroys MediaManager envelope instance.
345 * Decreases the use counter of the inner implementation.
350 * Opens the media access for specified with the url.
352 * If the \p preferred_attach_point parameter does not
353 * point to a usable attach point directory, the media
354 * manager automatically creates a temporary attach
355 * point in a default directory. This default directory
356 * can be changed using setAttachPrefix() function.
358 * Remember to close() each id you've opened and not
359 * need any more. It is like a new and delete!
361 * \param url The \ref MediaAccessUrl.
362 * \param preferred_attach_point The preferred, already
363 * existing directory, where the media should be
365 * \return a new media access id.
366 * \throws std::bad_alloc
367 * \throws MediaException
370 open(const Url &url, const Pathname & preferred_attach_point = "");
373 * Close the media access with specified id.
374 * \param accessId The media access id to close.
377 close(MediaAccessId accessId);
380 * Query if the media access is open / exists.
382 * \param accessId The media access id query.
383 * \return true, if access id is known and open.
386 isOpen(MediaAccessId accessId) const;
389 * Query the protocol name used by the media access
390 * handler. Similar to url().getScheme().
392 * \param accessId The media access id query.
393 * \return The protocol name used by the media access
394 * handler, otherwise 'unknown'.
395 * \throws MediaNotOpenException for invalid access id.
398 protocol(MediaAccessId accessId) const;
401 * Hint if files are downloaded or not.
404 downloads(MediaAccessId accessId) const;
407 * Returns the \ref MediaAccessUrl of the media access id.
409 * \throws MediaNotOpenException for invalid access id.
412 url(MediaAccessId accessId) const;
416 * Add verifier implementation for the specified media id.
417 * By default, the NoVerifier is used.
419 * \throws MediaNotOpenException for invalid access id.
422 addVerifier(MediaAccessId accessId,
423 const MediaVerifierRef &verifier);
426 * Remove verifier for specified media id.
428 * \throws MediaNotOpenException for invalid access id.
431 delVerifier(MediaAccessId accessId);
435 * Set or resets the directory name, where the media manager
436 * handlers create their temporary attach points (see open()
438 * It has effect to newly created temporary attach points only.
440 * \param attach_prefix The new prefix for temporary attach
441 * points, or empty pathname to reset to defaults.
442 * \return True on success, false if the \p attach_prefix
443 * parameters contains a path name, that does not
444 * point to a writable directory.
447 setAttachPrefix(const Pathname &attach_prefix);
450 * Attach the media using the concrete handler.
452 * Remember to release() or close() each id you've attached
453 * and not need any more. Attach is like an open of a file!
455 * \throws MediaNotOpenException for invalid access id.
458 attach(MediaAccessId accessId, bool next = false);
461 * Reattach to a new attach point.
463 * \deprecated This function will be removed, because the
464 * reattach function has race conditions (e.g. open file
465 * in the old attach point). Use setAttachPrefix() instead.
467 * \param accessId A media access Id.
468 * \param attach_point A new attach point directory.
469 * \param temporary Whether to reattach to a temporary
470 * attach point bellow of \p attach_point and cleanup
471 * it on release (temporary=true), or use the provided
472 * directory as attach point without to cleanup it on
473 * release (temporary=false, default behaviour).
474 * \throws MediaNotOpenException
475 * \throws MediaNotSupportedException
478 reattach(MediaAccessId accessId,
479 const Pathname &attach_point,
480 bool temporary = false) ZYPP_DEPRECATED;
483 * Release the attached media and optionally eject.
485 * \throws MediaNotOpenException for invalid access id.
488 release(MediaAccessId accessId, bool eject = false);
491 * Disconnect a remote media.
493 * This is useful for media which e.g. holds open a connection
494 * to a server like FTP. After calling disconnect() the media
495 * object (attach point) is still valid and files are present.
497 * But after calling disconnect() it's not possible to call
498 * fetch more data using the provideFile() or provideDir()
501 * \throws MediaNotOpenException for invalid access id.
504 disconnect(MediaAccessId accessId);
507 * Check if media is attached or not.
509 * \return True if media is attached.
510 * \throws MediaNotOpenException for invalid access id.
513 isAttached(MediaAccessId accessId) const;
516 * Returns information if media is on a shared
517 * physical device or not.
519 * \return True if it is shared, false if not.
520 * \throws MediaNotOpenException for invalid access id.
523 isSharedMedia(MediaAccessId accessId) const;
526 * Ask the registered verifier if the attached
527 * media is the desired one or not.
528 * \return True if media is attached and desired
529 * according to the actual verifier.
530 * \throws MediaNotOpenException for invalid access id.
533 isDesiredMedia(MediaAccessId accessId) const;
536 * Ask the specified verifier if the attached
537 * media is the desired one or not.
538 * \return True if media is attached and desired
539 * according to the specified verifier.
540 * \throws MediaNotOpenException for invalid access id.
543 isDesiredMedia(MediaAccessId accessId,
544 const MediaVerifierRef &verifier) const;
547 * Return the local directory that corresponds to medias url,
548 * no matter if media isAttached or not. Files requested will
549 * be available at 'localRoot() + filename' or even better
550 * 'localPath( filename )'
552 * \returns The directory name pointing to the media root
553 * in local filesystem or an empty pathname if the
554 * media is not attached.
555 * \throws MediaNotOpenException for invalid access id.
558 localRoot(MediaAccessId accessId) const;
561 * Shortcut for 'localRoot() + pathname', but returns an empty
562 * pathname if media is not attached.
563 * Files provided will be available at 'localPath(filename)'.
564 * \returns The directory name in local filesystem pointing
565 * to the desired relative pathname on the media
566 * or an empty pathname if the media is not attached.
567 * \throws MediaNotOpenException for invalid access id.
570 localPath(MediaAccessId accessId, const Pathname & pathname) const;
574 * Provide provide file denoted by relative path below of the
575 * 'attach point' of the specified media and the path prefix
578 * \param accessId The media access id to use.
579 * \param filename The filename to provide, relative on the media.
580 * \param cached If cached is set to true, the function checks, if
581 * the file already exists and doesn't download it again
582 * if it does. Currently only the existence is checked,
583 * no other file attributes.
584 * \param checkonly If this and 'cached' are set to true only the
585 * existence of the file is checked but it's not
586 * downloaded. If 'cached' is unset an errer is
589 * \throws MediaNotOpenException in case of invalid access id.
590 * \throws MediaNotAttachedException in case, that the media is not attached.
591 * \throws MediaNotDesiredException in case, that the media verification failed.
592 * \throws MediaNotAFileException in case, that the requested filename is not a file.
593 * \throws MediaFileNotFoundException in case, that the requested filenamedoes not exists.
594 * \throws MediaWriteException in case, that the file can't be copied from from remote source.
595 * \throws MediaSystemException in case a system operation fails.
596 * \throws MediaException derived exception, depending on the url (handler).
599 provideFile(MediaAccessId accessId,
600 const Pathname &filename,
602 bool checkonly = false) const;
607 provideDir(MediaAccessId accessId,
608 const Pathname &dirname) const;
613 provideDirTree(MediaAccessId accessId,
614 const Pathname &dirname) const;
619 releaseFile(MediaAccessId accessId,
620 const Pathname &filename) const;
625 releaseDir(MediaAccessId accessId,
626 const Pathname &dirname) const;
631 releasePath(MediaAccessId accessId,
632 const Pathname &pathname) const;
637 dirInfo(MediaAccessId accessId,
638 std::list<std::string> &retlist,
639 const Pathname &dirname,
640 bool dots = true) const;
645 dirInfo(MediaAccessId accessId,
646 filesystem::DirContent &retlist,
647 const Pathname &dirname,
648 bool dots = true) const;
653 getMountTableMTime() const;
655 std::vector<MountEntry>
656 getMountEntries() const;
659 isUseableAttachPoint(const Pathname &path) const;
662 friend class MediaHandler;
665 getAttachedMedia(MediaAccessId &accessId) const;
668 findAttachedMedia(const MediaSourceRef &media) const;
671 forceMediaRelease(const MediaSourceRef &media);
675 static zypp::RW_pointer<MediaManager::Impl> m_impl;
679 //////////////////////////////////////////////////////////////////
681 ////////////////////////////////////////////////////////////////////
683 ////////////////////////////////////////////////////////////////////
685 //////////////////////////////////////////////////////////////////////
687 #endif // ZYPP_MEDIA_MEDIAMANAGER_H
690 ** vim: set ts=2 sts=2 sw=2 ai et: