chr233 / ASFEnhance

ASF 扩展命令插件 / External commands for ASF
GNU Affero General Public License v3.0
500 stars 41 forks source link

Replacing a new plugin file if the backup file already exists #37

Closed xTCry closed 1 year ago

xTCry commented 1 year ago

A problem has been identified that when updating the plugin again, without restarting ASF, an error occurs when creating a backup again.

2022-11-23 11:57:42|ArchiSteamFarm-244142|ERROR|ASF|ResponseUpdatePlugin() System.IO.IOException: The file '/app/plugins/ASFEnhance.bak' already exists.
   at System.IO.FileSystem.LinkOrCopyFile(String , String )
   at System.IO.FileSystem.MoveFile(String , String , Boolean )
   at System.IO.File.Move(String , String , Boolean )
   at ASFEnhance.Update.Command.ResponseUpdatePlugin()

A solution to the problem: Replacing a new plugin file if the backup file already exists

chr233 commented 1 year ago

you can try replace the plugin's dll manually, this error may caused by file permission configure error.

xTCry commented 1 year ago

Yes, it is logical that can replace file manually (which I had to do in the end). It's just convenient when there is an opportunity to update the plugin from browser on phone.

xTCry commented 1 year ago

Maybe it's worth adding a check for an already existing backup file, and if possible, just do not replace it?

https://github.com/chr233/ASFEnhance/blob/2aed306f8579b6be876549b0ae3870dee460e4e1/ASFEnhance/Update/Command.cs#L112

+ bool existsBackup = File.Exists(backupPath);
-  File.Move(currentPath, backupPath);
+ if (!existsBackup) {
+     File.Move(currentPath, backupPath);
+ }

In this case, the last working plugin will be deleted after a successful restart of ASF or restored if an error occurs.