Ensure the file is released helper method.
(filePath string)
| 123 | |
| 124 | // Ensure the file is released helper method. |
| 125 | func (p powershell) ensureFileReleased(filePath string) error { |
| 126 | // Try to open the file multiple times to ensure it's released. |
| 127 | for range 3 { |
| 128 | file, err := os.OpenFile(filePath, os.O_RDONLY, 0644) |
| 129 | if err != nil { |
| 130 | // If the file cannot be opened, it may not exist or there may be other errors. |
| 131 | if os.IsNotExist(err) { |
| 132 | return fmt.Errorf("file does not exist: %s", filePath) |
| 133 | } |
| 134 | continue // Other errors, keep retrying |
| 135 | } |
| 136 | file.Close() |
| 137 | return nil // If the file can be opened and closed, it means it's released. |
| 138 | } |
| 139 | return fmt.Errorf("file is still locked after multiple attempts: %s", filePath) |
| 140 | } |
| 141 | |
| 142 | func (p powershell) uninstallCompletion() error { |
| 143 | // Unregister completion ps file. |