Skip to content

Commit

Permalink
🐛 #1101 read-only issue (Squashed commit)
Browse files Browse the repository at this point in the history
commit 3280158
Author: lorinczandrea <[email protected]>
Date:   Mon Oct 21 19:52:15 2024 +0200

    :bug: _removeReadOnlyAttribute()

    #1101

commit aca63ee
Author: lorinczandrea <[email protected]>
Date:   Fri Oct 18 14:15:13 2024 +0200

    :construction: read only dir. attribute deleted

    need more tests

    #1101
  • Loading branch information
lorinczandrea committed Oct 21, 2024
1 parent 0edc9c0 commit 269b156
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
39 changes: 38 additions & 1 deletion FemDesign.Core/FemDesignConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,16 +1065,27 @@ public void Dispose()
// TODO: Delete the files when they are not locked by FEM-Design
this._deleteOutputDirectories();
}

private void _deleteOutputDirectories()
{
foreach (string dir in _outputDirsToBeDeleted)
if (Directory.Exists(dir))
_deleteFolderIfNotUsed(dir);
}

private static void _deleteFolderIfNotUsed(string folderPath)
{
_removeReadOnlyAttribute(folderPath, out List<string> subDirectories);

try
{
// update directory info
foreach (var dir in subDirectories)
{
var directoryInfo = new DirectoryInfo(dir);
directoryInfo.Refresh();
}

Directory.Delete(folderPath, true);
}
catch (IOException ex)
Expand All @@ -1090,6 +1101,32 @@ private static void _deleteFolderIfNotUsed(string folderPath)
}
}

private static void _removeReadOnlyAttribute(string folderPath, out List<string> subDirectories)
{
// get directories & subdirectories
subDirectories = new List<string> { folderPath };
int i = 0;
while (i < subDirectories.Count)
{
var subSubDirs = Directory.GetDirectories(subDirectories[i]).ToList();
if (subSubDirs?.Count > 0)
subDirectories.AddRange(subSubDirs);

i++;
}

// check if directory is read-only
foreach (var dir in subDirectories)
{
var directoryInfo = new DirectoryInfo(dir);
if ((directoryInfo.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
{
// Remove read-only attribute
directoryInfo.Attributes &= ~FileAttributes.ReadOnly;
}
}
}

/// <summary>
/// Create .bsc files, and return the .bsc and .csv file paths.
/// </summary>
Expand Down Expand Up @@ -1781,7 +1818,7 @@ public static string GetFdScriptPath(string baseDir, string fileName = "script")
{
string dir = Path.Combine(baseDir, _scriptsDirectory);
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
Directory.CreateDirectory(dir);
fileName = Path.GetFileName(Path.ChangeExtension(fileName, _fdscriptFileExtension));
string path = Path.GetFullPath(Path.Combine(dir, fileName));
return path;
Expand Down
3 changes: 1 addition & 2 deletions FemDesign.Core/Sections/Section.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Xml.Serialization;
using FuzzySharp.Extractor;
using System.IO;

namespace FemDesign.Sections
{
Expand Down Expand Up @@ -281,8 +282,6 @@ public static Results.SectionProperties GetSectionProperties(this Section sectio
units.SectionalData = sectionUnits;

secProp = femDesign._getResults<Results.SectionProperties>(units, timeStamp: true);

//femDesign.Disconnect(); // Check this. FEM-Design should not be left open after the process!
}

// Method that reorder the secProp list to match the input order using the section name
Expand Down

0 comments on commit 269b156

Please sign in to comment.