summaryrefslogtreecommitdiff
path: root/packages/nxcl/files/deletelogfiles.patch
blob: 9e5b10dcca933f29855c7f1ee161406fefa4346b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
Index: nxcl-0.9/lib/nxclientlib.cpp
===================================================================
--- nxcl-0.9.orig/lib/nxclientlib.cpp	2008-10-15 15:09:17.000000000 +0200
+++ nxcl-0.9/lib/nxclientlib.cpp	2008-10-15 15:30:33.000000000 +0200
@@ -27,6 +27,8 @@
 #include "../config.h"
 
 #include <fstream>
+#include <iostream>
+#include <string>
 
 extern "C" {
     #include <errno.h>
@@ -966,4 +968,68 @@
     free (buf);
     return path;
 }
+
+int NXClientLib::fmatch(const struct dirent *direntry)
+{
+        if (strncmp(direntry->d_name, "S", 1) == 0){
+                return 1;
+        }
+        return 0;
+}
+
+
+bool NXClientLib::deleteAllSessionfiles()
+{
+    struct dirent **filelist;
+    DIR *Directory;
+    int filescount = 0;
+    int i;
+    ifstream sessionfile;
+    string line, rmsesdir;
+
+    char * home;
+    stringstream ss;
+    string nxdir;
+
+    home = getenv ("HOME");
+
+    ss << home;
+
+    nxdir = ss.str() + "/.nx";
+
+    Directory = opendir(nxdir.c_str());
+
+    if( Directory )
+    {
+       filescount = scandir(nxdir.c_str(), &filelist, fmatch, alphasort);
+
+       for (i=0; i < filescount; i++)
+       {
+                rmsesdir = nxdir + "/" + string(filelist[i]->d_name) + "/";
+                sessionfile.open((rmsesdir + "session").c_str());
+
+                if ( sessionfile.is_open() )
+                {
+                    while( !sessionfile.eof() )
+                    {
+                        getline(sessionfile,line);
+                        if ( (line.find("Session terminated") != string::npos) ||
+				(line.find("Exiting keeper") != string::npos) )
+                        {
+                                // lazy deletion but it works
+                                remove( (rmsesdir + "errors").c_str() );
+                                remove( (rmsesdir + "options").c_str() );
+                                remove( (rmsesdir + "session").c_str() );
+                                remove( (rmsesdir + "stats").c_str() );
+                                remove(rmsesdir.c_str());
+                                break;
+                        }
+                    }
+                }
+       }
+       return true;
+     }
+     return false;
+}
+
 //@}
Index: nxcl-0.9/lib/nxclientlib.h
===================================================================
--- nxcl-0.9.orig/lib/nxclientlib.h	2008-10-15 15:09:17.000000000 +0200
+++ nxcl-0.9/lib/nxclientlib.h	2008-10-15 15:09:17.000000000 +0200
@@ -25,10 +25,14 @@
 #define _NXCLIENTLIB_H_
 
 #include <iostream>
-#include "nxsession.h"
 #include <list>
+
+#include "nxsession.h"
 #include "notQt.h"
 
+extern "C" {
+	    #include <dirent.h>
+}
 
 using namespace std;
 
@@ -375,6 +379,11 @@
             {
                 return this->sessionRunning;
             }
+
+	    // static function so we do not need an explicit object
+	    // for deleting the session files
+	    static bool deleteAllSessionfiles(void);
+
             //@}
 
         private:
@@ -493,6 +502,7 @@
              */
             int httpProxyPort;
 
+	    static int fmatch(const struct dirent *direntry);
     };
 
 } // namespace
Index: nxcl-0.9/lib/nxdata.h
===================================================================
--- nxcl-0.9.orig/lib/nxdata.h	2008-10-15 15:09:17.000000000 +0200
+++ nxcl-0.9/lib/nxdata.h	2008-10-15 15:09:17.000000000 +0200
@@ -77,6 +77,9 @@
         bool proxyAuthenticated;
         string proxyUser;
         string proxyPass;
+	// small hack for storing this
+	// easier than workaround in the client
+	bool delSessionfiles;
     };
 
     struct NXSessionData {