add sat::WhatProvides to look for Solvable providing a Capability. (somtimes segfaults).
[platform/upstream/libzypp.git] / tests / media / media4.cc
1 #include <zypp/media/MediaManager.h>
2 #include <zypp/base/String.h>
3 #include <zypp/base/Logger.h>
4 #include <zypp/Pathname.h>
5 #include <zypp/PathInfo.h>
6 #include <zypp/TmpPath.h>
7 #include <zypp/ExternalProgram.h>
8
9 #include <string>
10 #include <list>
11 #include <iostream>
12 #include <cstdlib>
13
14 #include <signal.h>
15 #include <stdlib.h>
16
17 using namespace zypp;
18 using namespace zypp::media;
19
20 bool       do_step = false;
21 int        do_quit = 0;
22
23 void quit(int)
24 {
25     do_quit = 1;
26 }
27
28 void goon(int)
29 {
30 }
31
32 #define ONE_STEP(MSG) \
33 do { \
34   DBG << "======================================" << std::endl; \
35   DBG << "==>> " << MSG << std::endl; \
36   DBG << "======================================" << std::endl; \
37   if( do_step) { pause(); if( do_quit) exit(0); } \
38 } while(0);
39
40 int main(int argc, char *argv[])
41 {
42   {
43       struct sigaction sa;
44       sigemptyset(&sa.sa_mask);
45       sa.sa_flags   = 0;
46       sa.sa_handler = goon;
47       sigaction(SIGINT,  &sa, NULL);
48       sa.sa_handler = quit;
49       sigaction(SIGTERM, &sa, NULL);
50
51       if( argc > 1 && std::string(argv[1]) == "-i")
52         do_step = true;
53   }
54
55   MediaManager     mm;
56   media::MediaId   id;
57   zypp::Url        url;
58   Pathname         dir("./suse/setup/descr");
59
60   url = "cd:/";
61
62   try
63   {
64     ONE_STEP("open " + url.asString());
65     id = mm.open(url);
66
67     ONE_STEP("attach")
68     mm.attach(id);
69
70     ONE_STEP("provideDirTree(" + dir.asString() + ")");
71     mm.provideDirTree(id, Pathname(dir));
72
73     ONE_STEP("Create a temporary dir");
74     zypp::filesystem::TmpDir temp;
75
76     ONE_STEP("Create a copy of " + dir.asString());
77     zypp::filesystem::copy_dir(mm.localPath(id, dir), temp.path());
78
79     std::string cmd("/bin/ls -lR ");
80                 cmd += temp.path().asString();
81
82     ONE_STEP("Check the directory copy")
83     system( cmd.c_str());
84
85     ONE_STEP("CLEANUP")
86   }
87   catch(const MediaException &e)
88   {
89     ZYPP_CAUGHT(e);
90   }
91   catch( ... )
92   {
93     // hmm...
94     ERR << "Catched *unknown* exception" << std::endl;
95   }
96
97   return 0;
98 }
99
100 // vim: set ts=2 sts=2 sw=2 ai et: