Skip to content

Commit

Permalink
closing file before removing it
Browse files Browse the repository at this point in the history
Signed-off-by: Kapil Sharma <[email protected]>
  • Loading branch information
h4l0gen authored Apr 9, 2024
1 parent c04d7ae commit 6728db0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions events/syscall/update_package_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package syscall

import (
Expand All @@ -30,12 +29,15 @@ func UpdatePackageRepository(h events.Helper) error {

// Check if the file exists
if _, err := os.Stat(path); err != nil {
// If the file doesn't exist, create it
_, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, os.FileMode(0755))
// If the file doesn't exist, create it and open it in write only mode
file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, os.FileMode(0755))
if err != nil {
return err
}
defer os.Remove(path)
defer file.Close()
// Remove file after closing it to free file occupied space
os.Remove(path)

} else {
// If the file exists, open it for writing
file, err := os.OpenFile(path, os.O_WRONLY, os.FileMode(0755))
Expand Down

0 comments on commit 6728db0

Please sign in to comment.