[chronojump] CopyFilesRecursively takes care of disk full in copy files and create dirs
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] CopyFilesRecursively takes care of disk full in copy files and create dirs
- Date: Sat, 21 Aug 2021 09:41:24 +0000 (UTC)
commit aaa8ae5f63d811441cc0ac5aa95339e978c6fe9c
Author: Xavier de Blas <xaviblas gmail com>
Date: Sat Aug 21 11:40:36 2021 +0200
CopyFilesRecursively takes care of disk full in copy files and create dirs
src/util.cs | 33 ++++++++++++++++++++++++++-------
1 file changed, 26 insertions(+), 7 deletions(-)
---
diff --git a/src/util.cs b/src/util.cs
index ef2297cdb..2ba769268 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -2551,7 +2551,7 @@ public class UtilCopy
}
//http://stackoverflow.com/a/58779
- public void CopyFilesRecursively(DirectoryInfo source, DirectoryInfo target, uint level)
+ public bool CopyFilesRecursively(DirectoryInfo source, DirectoryInfo target, uint level)
{
DirectoryInfo [] diArray = source.GetDirectories();
foreach (DirectoryInfo dir in diArray)
@@ -2591,15 +2591,34 @@ public class UtilCopy
continue;
}
}
- CopyFilesRecursively(dir, target.CreateSubdirectory(dir.Name), level +1);
+
+ //create new dir with try/catch to avoid disk problems (eg. disk full)
+ DirectoryInfo newTarget;
+ try {
+ newTarget = target.CreateSubdirectory(dir.Name);
+ } catch {
+ return false;
+ }
+
+ if(! CopyFilesRecursively(dir, newTarget, level +1))
+ return false; //exit if disk problem found in that call
}
- foreach (FileInfo file in source.GetFiles())
- {
- if(file.Name == "chronojump_running") //do not copy chronojump_running file
- continue;
- file.CopyTo(Path.Combine(target.FullName, file.Name));
+ //copy files with try/catch to avoid disk problems (eg. disk full)
+ try {
+ foreach (FileInfo file in source.GetFiles())
+ {
+ if(file.Name == "chronojump_running") //do not copy chronojump_running file
+ continue;
+
+ file.CopyTo(Path.Combine(target.FullName, file.Name));
+ }
+ } catch {
+ LogB.Warning("CopyFilesRecursively catched, maybe disk full");
+ return false;
}
+
+ return true;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]