OSDN Git Service

na-get-lib,チケット #26588 (ソフトウェアインストールの)異常終了後に AppliStation が起動不可になる問題の本対処
[applistation/AppliStation.git] / na-get-lib / NaGet.SubCommands.SubTask / LocalUpdateSubTask.cs
index f729241..73c525c 100644 (file)
@@ -1,4 +1,5 @@
 using System;
+using System.IO;
 using NaGet.Tasks;
 using NaGet.Packages;
 
@@ -18,7 +19,11 @@ namespace NaGet.SubCommands.SubTask
                        NotifyStarted();
                        RaiseTaskSetEvent(TaskEventType.STARTED, "インストール済みファイルリスト更新", 0);
                        
-                       pkgListMan.DetectInstalledPkgs();
+                       try {
+                               pkgListMan.DetectInstalledPkgs();
+                       } catch (PackageInformationFileAccessException e) {
+                               recoverExceptionAtDetectInstalledPkgs(e);
+                       }
                        pkgListMan.SaveInstalledPackageList();
                        RaiseTaskSetEvent(TaskEventType.INFO, string.Format("{0} を更新しました", NaGet.Env.ArchiveInstalledPackageListFile), 50);
                        
@@ -29,5 +34,21 @@ namespace NaGet.SubCommands.SubTask
                        RaiseTaskSetEvent(TaskEventType.COMPLETED, "インストール済みファイルリスト更新", 100);
                        NotifyCompleted();
                }
+               
+               private void recoverExceptionAtDetectInstalledPkgs(PackageInformationFileAccessException e)
+               {
+                       RaiseTaskSetEvent(TaskEventType.WARNING, string.Format("{0} が読み込めませんでした", e.FilePath), -1);
+                       
+                       string dirPath = Path.GetDirectoryName(e.FilePath);
+                       if (Directory.Exists(dirPath)) {
+                               NaGet.Utils.SetAttributeRecursive(dirPath, FileAttributes.Normal);
+                               Directory.Delete(dirPath, true);
+                               RaiseTaskSetEvent(TaskEventType.WARNING, string.Format("{0}を削除しました。", Path.GetDirectoryName(e.FilePath)), -1);
+                               
+                               pkgListMan.DetectInstalledPkgs();
+                       } else {
+                               throw e;
+                       }
+               }
        }
 }