Changeset 5327
- Timestamp:
- 01/18/11 16:52:20 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/PluginCache.cs
r5325 r5327 26 26 using System.Reflection; 27 27 using System.Runtime.CompilerServices; 28 using System.Runtime.Serialization; 29 using System.Runtime.Serialization.Formatters.Binary; 28 30 using System.Threading; 29 31 using HeuristicLab.Services.Hive.Common.DataTransfer; … … 33 35 private static object locker = new object(); 34 36 public const string ConfigFileName = "Sandbox.config"; 37 private const string lastUsedFileName = "lastUsed.dat"; 38 39 //maximum number of days after which a plugin gets deleted if not used 40 private const int maxAge = 5; 35 41 36 42 private static PluginCache instance = null; … … 95 101 string curPath = Path.Combine(PluginCacheDir, requestedPlugin.Id.ToString()); 96 102 if (Directory.Exists(curPath)) { 103 writeDateLastUsed(curPath); 104 97 105 foreach (string file in Directory.GetFiles(curPath)) { 98 106 string fn = getFilenameFromPath(file); 99 File.Copy(file, Path.Combine(targetDir, fn)); 107 if (fn != lastUsedFileName) 108 File.Copy(file, Path.Combine(targetDir, fn)); 100 109 } 101 110 } … … 183 192 } 184 193 } 194 195 /// <summary> 196 /// creates a file in path with the current date; 197 /// this can later be used to find plugins which are outdated 198 /// </summary> 199 private void writeDateLastUsed(string path) { 200 FileStream fs = new FileStream(Path.Combine(path, lastUsedFileName), FileMode.Create); 201 BinaryFormatter formatter = new BinaryFormatter(); 202 203 try { 204 formatter.Serialize(fs, DateTime.Now); 205 } 206 catch (SerializationException) { 207 //rethrow... 208 throw; 209 } 210 finally { 211 fs.Close(); 212 } 213 } 214 215 /// <summary> 216 /// checks the pluginCacheDirectory and deletes plugin folders which are not used anymore 217 /// </summary> 218 /// <param name="path"></param> 219 private void cleanPluginCache() { 220 FileStream fs = null; 221 DateTime luDate; 222 bool changed = false; 223 224 if (Directory.Exists(PluginCacheDir)) { 225 foreach (string dir in Directory.EnumerateDirectories(PluginCacheDir)) { 226 try { 227 fs = new FileStream(Path.Combine(dir, lastUsedFileName), FileMode.Open); 228 BinaryFormatter formatter = new BinaryFormatter(); 229 luDate = (DateTime)formatter.Deserialize(fs); 230 fs.Close(); 231 232 if (luDate.AddDays(maxAge) < DateTime.Now) { 233 Directory.Delete(dir, true); 234 changed = true; 235 } 236 } 237 catch (SerializationException) { 238 fs.Close(); 239 throw; 240 } 241 catch (System.IO.FileNotFoundException) { 242 //nerver used 243 Directory.Delete(dir, true); 244 changed = true; 245 } 246 catch (Exception) { 247 throw; 248 } 249 } 250 } 251 if (changed) 252 DoUpdateRun(); 253 } 254 185 255 186 256 internal void DeletePluginsForJob(Guid id) { … … 203 273 SlaveClientCom.Instance.ClientCom.LogMessage("failed while unloading " + id + " with exception " + ex); 204 274 } 275 cleanPluginCache(); 205 276 } 206 277 }
Note: See TracChangeset
for help on using the changeset viewer.