Skip to content
Snippets Groups Projects
Commit 13b17e22 authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Be more careful when resetting the ACLs.

Catch exceptions in case setting the ACLs fails, make the operation
optional by adding the parameter resetAcls (defaulting to false).

Refers to #16
parent b0d7b8ba
No related branches found
No related tags found
No related merge requests found
...@@ -673,7 +673,7 @@ namespace AutoTx ...@@ -673,7 +673,7 @@ namespace AutoTx
writeLogDebug("Finalizing transfer, cleaning up target storage location..."); writeLogDebug("Finalizing transfer, cleaning up target storage location...");
var finalDst = DestinationPath(_status.CurrentTargetTmp); var finalDst = DestinationPath(_status.CurrentTargetTmp);
if (!string.IsNullOrWhiteSpace(finalDst)) { if (!string.IsNullOrWhiteSpace(finalDst)) {
if (MoveAllSubDirs(new DirectoryInfo(ExpandCurrentTargetTmp()), finalDst)) { if (MoveAllSubDirs(new DirectoryInfo(ExpandCurrentTargetTmp()), finalDst, true)) {
_status.CurrentTargetTmp = ""; _status.CurrentTargetTmp = "";
} }
} }
...@@ -853,7 +853,7 @@ namespace AutoTx ...@@ -853,7 +853,7 @@ namespace AutoTx
/// <param name="sourceDir">The source path as DirectoryInfo object.</param> /// <param name="sourceDir">The source path as DirectoryInfo object.</param>
/// <param name="destPath">The destination path as a string.</param> /// <param name="destPath">The destination path as a string.</param>
/// <returns>True on success, false otherwise.</returns> /// <returns>True on success, false otherwise.</returns>
private bool MoveAllSubDirs(DirectoryInfo sourceDir, string destPath) { private bool MoveAllSubDirs(DirectoryInfo sourceDir, string destPath, bool resetAcls = false) {
// TODO: check whether _transferState should be adjusted while moving dirs! // TODO: check whether _transferState should be adjusted while moving dirs!
writeLogDebug("MoveAllSubDirs: " + sourceDir.FullName + " to " + destPath); writeLogDebug("MoveAllSubDirs: " + sourceDir.FullName + " to " + destPath);
try { try {
...@@ -872,10 +872,17 @@ namespace AutoTx ...@@ -872,10 +872,17 @@ namespace AutoTx
writeLogDebug(" - " + subDir.Name + " > " + target); writeLogDebug(" - " + subDir.Name + " > " + target);
subDir.MoveTo(target); subDir.MoveTo(target);
if (_config.EnforceInheritedACLs) { if (resetAcls && _config.EnforceInheritedACLs) {
var acl = Directory.GetAccessControl(target); try {
acl.SetAccessRuleProtection(false, false); var acl = Directory.GetAccessControl(target);
Directory.SetAccessControl(target, acl); acl.SetAccessRuleProtection(false, false);
Directory.SetAccessControl(target, acl);
writeLogDebug("Successfully reset inherited ACLs on " + target);
}
catch (Exception ex) {
writeLog("Error resetting inherited ACLs on " + target + ":\n" +
ex.Message);
}
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment