Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions internal/adapters/apis/docker/docker_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,27 @@ func (d *DockerAdapter) ensureImage(ctx context.Context, imageName string) error

return nil
}

// RemoveVolumeData removes all data from a Docker volume by deleting its contents
func (d *DockerAdapter) RemoveVolumeData(ctx context.Context, volumeTargetPath string) error {
// remove all files in the volume target path
dirEntries, err := os.ReadDir(volumeTargetPath)
if err != nil {
return fmt.Errorf("failed to read volume directory: %w", err)
}

for _, entry := range dirEntries {
entryPath := fmt.Sprintf("%s/%s", volumeTargetPath, entry.Name())
if entry.IsDir() {
if err := os.RemoveAll(entryPath); err != nil {
return fmt.Errorf("failed to remove directory %s: %w", entryPath, err)
}
} else {
if err := os.Remove(entryPath); err != nil {
return fmt.Errorf("failed to remove file %s: %w", entryPath, err)
}
}
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ func (s *SnapshotManagerAdapter) StopDownload(ctx context.Context, clientShortNa
containerName := fmt.Sprintf("%s%s", downloadContainerPrefix, clientShortName)
_ = s.docker.StopContainerWithTimeout(ctx, containerName, 5)
}

// ClearExecutionClientData removes existing data for the execution client
func (s *SnapshotManagerAdapter) ClearExecutionClientData(ctx context.Context, client domain.ExecutionClientInfo) error {
return s.docker.RemoveVolumeData(ctx, client.VolumeName)
}
3 changes: 3 additions & 0 deletions internal/application/ports/snapshotChecker_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ type SnapshotManager interface {

// StopDownload stops the snapshot download container for a specific client
StopDownload(ctx context.Context, clientShortName string)

// ClearExecutionClientData removes existing data for the execution client
ClearExecutionClientData(ctx context.Context, client domain.ExecutionClientInfo) error
}
6 changes: 6 additions & 0 deletions internal/application/services/snapshot_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ func (s *SnapshotCheckerService) checkAndUpdateSnapshot(ctx context.Context) err

logger.InfoWithPrefix(snapshotLogPrefix, "[%s] Snapshot download needed", client.ShortName)

// Remove ec volume data before downloading new snapshot
logger.InfoWithPrefix(snapshotLogPrefix, "[%s] Removing existing volume data before snapshot download...", client.ShortName)
if err := s.snapshotManager.ClearExecutionClientData(ctx, client); err != nil {
return fmt.Errorf("failed to clear execution client data: %w", err)
}

// Set download in progress for this client
logger.InfoWithPrefix(snapshotLogPrefix, "[%s] Setting download in progress marker...", client.ShortName)
if err := s.downloadProgress.SetDownloadInProgress(ctx); err != nil {
Expand Down