Directory: | ./ |
---|---|
File: | build/phoenix_base_uninstall_main.cpp |
Date: | 2025-03-14 12:18:05 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 24 | 29 | 82.8% |
Branches: | 30 | 58 | 51.7% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /*************************************** | ||
2 | Auteur : Pierre Aubert | ||
3 | Mail : aubertp7@gmail.com | ||
4 | Licence : CeCILL-C | ||
5 | ****************************************/ | ||
6 | |||
7 | #include <stdio.h> | ||
8 | #include <stdlib.h> | ||
9 | #include <iostream> | ||
10 | #include <string> | ||
11 | #include <fstream> | ||
12 | |||
13 | ///Remove a directory | ||
14 | /** @param dir : directory to suppress | ||
15 | * @return true on success, false otherwise | ||
16 | */ | ||
17 | 1 | bool removeDirectory(const std::string & dir){ | |
18 |
1/1✓ Branch 1 taken 1 times.
|
1 | std::string commande("rm -rf " + dir); |
19 |
2/3✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | if(system(commande.c_str()) != 0){ |
20 | ✗ | std::cerr << "can't remove directory '" << dir << "'" << std::endl; | |
21 | ✗ | return false; | |
22 | } | ||
23 | 1 | return true; | |
24 | 1 | } | |
25 | |||
26 | 1 | int main(int argc, char** argv){ | |
27 |
1/1✓ Branch 2 taken 1 times.
|
1 | std::string installManifest("/usr/share/Phoenix/uninstall/PhoenixSwarm/install_manifest.txt"); |
28 |
1/1✓ Branch 1 taken 1 times.
|
1 | std::ifstream fs; |
29 |
1/1✓ Branch 2 taken 1 times.
|
1 | fs.open(installManifest.c_str()); |
30 |
2/3✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
|
1 | if(!fs.is_open()){ |
31 | ✗ | std::cerr << "Can't open file '" << installManifest << "'" << std::endl; | |
32 | ✗ | return -1; | |
33 | } | ||
34 | int ch; | ||
35 | do{ | ||
36 |
1/1✓ Branch 2 taken 160 times.
|
160 | std::string line(""); |
37 |
1/1✓ Branch 1 taken 160 times.
|
160 | ch = fs.get(); |
38 |
4/4✓ Branch 0 taken 7436 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 7277 times.
✓ Branch 3 taken 159 times.
|
7437 | while(ch != EOF && (char)ch != '\n'){ |
39 |
1/1✓ Branch 1 taken 7277 times.
|
7277 | line += (char)ch; |
40 |
1/1✓ Branch 1 taken 7277 times.
|
7277 | ch = fs.get(); |
41 | } | ||
42 |
2/3✓ Branch 1 taken 160 times.
✓ Branch 3 taken 160 times.
✗ Branch 4 not taken.
|
160 | if(line != ""){ |
43 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 160 times.
|
160 | if(remove(line.c_str()) != 0){ |
44 | ✗ | std::cerr << "Can't remove file '" << line << "'" << std::endl; | |
45 | }else{ | ||
46 |
4/4✓ Branch 1 taken 160 times.
✓ Branch 4 taken 160 times.
✓ Branch 7 taken 160 times.
✓ Branch 10 taken 160 times.
|
160 | std::cerr << "Remove file '" << line << "'" << std::endl; |
47 | } | ||
48 | } | ||
49 |
2/2✓ Branch 1 taken 159 times.
✓ Branch 2 taken 1 times.
|
160 | }while(ch != EOF); |
50 |
1/1✓ Branch 1 taken 1 times.
|
1 | fs.close(); |
51 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
|
1 | removeDirectory("/usr/share/Phoenix/uninstall/PhoenixSwarm"); |
52 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
|
1 | std::cerr << "Uninstall all files from the " << std::endl; |
53 | 1 | return 0; | |
54 | 1 | } | |
55 | |||
56 | |||
57 | |||
58 | |||
59 | |||
60 | |||
61 |