root/branches/bud/sss/uninstall.d

Revision 178, 2.6 kB (checked in by Gregor, 2 years ago)

2006-12-20 gregor

*: Installations now put relative paths in the manifest file.

Line 
1 /**
2  * DSSS command "uninstall"
3  *
4  * Authors:
5  *  Gregor Richards
6  *
7  * License:
8  *  Copyright (c) 2006  Gregor Richards
9  * 
10  *  Permission is hereby granted, free of charge, to any person obtaining a
11  *  copy of this software and associated documentation files (the "Software"),
12  *  to deal in the Software without restriction, including without limitation
13  *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  *  and/or sell copies of the Software, and to permit persons to whom the
15  *  Software is furnished to do so, subject to the following conditions:
16  * 
17  *  The above copyright notice and this permission notice shall be included in
18  *  all copies or substantial portions of the Software.
19  * 
20  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  *  DEALINGS IN THE SOFTWARE.
27  */
28
29 module sss.uninstall;
30
31 import sss.clean;
32 import sss.conf;
33
34 import std.file;
35 import std.path;
36 import std.stdio;
37 import std.string;
38
39 /** Entry to the "uninstall" function */
40 int uninstall(char[][] toolList)
41 {
42     foreach (tool; toolList)
43     {
44         // uninstall this tool
45         char[] manifestFile = manifestPrefix ~ std.path.sep ~ tool ~ ".manifest";
46         if (!exists(manifestFile)) {
47             writefln("Tool " ~ tool ~ " is not installed.");
48             return 1;
49         }
50        
51         writefln("Uninstalling %s", tool);
52        
53         // get the list
54         char[][] manifest = std.string.split(
55             cast(char[]) std.file.read(manifestFile),
56             "\n");
57        
58         // then delete them
59         foreach (file; manifest) {
60             if (file != "") {
61                 // if it's not absolute, infer the absolute path
62                 if (!isabs(file)) {
63                     file = forcePrefix ~ std.path.sep ~ file;
64                 }
65                
66                 writefln("Removing %s", file);
67                 tryRemove(file);
68             }
69         }
70        
71         writefln("");
72     }
73    
74     return 0;
75 }
76
77 /** Entry to the "installed" function */
78 int installed()
79 {
80     foreach (pkg; listdir(manifestPrefix).sort)
81     {
82         if (pkg.length < 9 || pkg[$-9 .. $]  != ".manifest") continue;
83         pkg = pkg[0 .. $-9];
84        
85         writefln("%s", pkg);
86     }
87    
88     return 0;
89 }
Note: See TracBrowser for help on using the browser.