Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5787


Ignore:
Timestamp:
03/22/11 12:46:37 (14 years ago)
Author:
cneumuel
Message:

#1233

  • made deleting and creating directories for PluginTemp more robust
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/PluginCache.cs

    r5721 r5787  
    7070
    7171    private void DoUpdateRun() {
    72       if (!Directory.Exists(PluginCacheDir)) {
    73         Directory.CreateDirectory(PluginCacheDir);
    74       }
    75 
     72      SafelyCreateDirectory(PluginCacheDir);
    7673      foreach (string dir in Directory.EnumerateDirectories(PluginCacheDir)) {
    7774        cachedPluginsGuids.Add(Guid.Parse(GetFilenameFromPath(dir))); // Todo: cleaner solution to getFilenameFromPath
     
    8582        String targetDir = Path.Combine(PluginTempBaseDir, jobId.ToString());
    8683
    87         if (Directory.Exists(targetDir)) {
    88           Directory.Delete(targetDir, true);
    89         }
    90         Directory.CreateDirectory(targetDir);
     84        RecreateDirectory(targetDir);
    9185
    9286        foreach (Plugin requestedPlugin in requests) {
     
    116110    }
    117111
     112    private static DirectoryInfo RecreateDirectory(String targetDir) {
     113      var di = new DirectoryInfo(targetDir);
     114      if (di.Exists) Directory.Delete(targetDir, true);
     115      di.Refresh();
     116      while (di.Exists) {
     117        Thread.Sleep(50);
     118        di.Refresh();
     119      }
     120      return SafelyCreateDirectory(targetDir);
     121    }
     122
     123    private static DirectoryInfo SafelyCreateDirectory(String targetDir) {
     124      var di = new DirectoryInfo(targetDir);
     125      if (!di.Exists) {
     126        di = Directory.CreateDirectory(targetDir);
     127        while (!di.Exists) {
     128          Thread.Sleep(50);
     129          di.Refresh();
     130        }
     131      }
     132      return di;
     133    }
     134
    118135    private void CopyFile(string baseDir, string targetDir, string fileName) {
    119136      if (!File.Exists(Path.Combine(targetDir, fileName))) File.Copy(Path.Combine(baseDir, fileName), Path.Combine(targetDir, fileName));
     
    164181
    165182          //put all files belonging to a plugin in the same directory
    166           if (!Directory.Exists(pluginDir)) {
    167             DirectoryInfo di = Directory.CreateDirectory(pluginDir);
    168           }
     183          SafelyCreateDirectory(pluginDir);
    169184          File.WriteAllBytes(Path.Combine(pluginDir, Path.GetFileName(pluginData.FileName)), pluginData.Data);
    170185        }
Note: See TracChangeset for help on using the changeset viewer.