mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-05 05:20:34 +00:00
This commit is contained in:
+51
-1
@@ -16,9 +16,16 @@ import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
// RemoteRepo statuses
|
||||
const (
|
||||
MirrorIdle = iota
|
||||
MirrorUpdating
|
||||
)
|
||||
|
||||
// RemoteRepo represents remote (fetchable) Debian repository.
|
||||
//
|
||||
// Repostitory could be filtered when fetching by components, architectures
|
||||
@@ -49,8 +56,14 @@ type RemoteRepo struct {
|
||||
Filter string
|
||||
// FilterWithDeps to include dependencies from filter query
|
||||
FilterWithDeps bool
|
||||
// Status marks state of repository (being updated, no action)
|
||||
Status int
|
||||
// WorkerPID is PID of the process modifying the mirror (if any)
|
||||
WorkerPID int
|
||||
// "Snapshot" of current list of packages
|
||||
packageRefs *PackageRefList
|
||||
// Temporary list of package refs
|
||||
tempPackageRefs *PackageRefList
|
||||
// Parsed archived root
|
||||
archiveRootURL *url.URL
|
||||
// Current list of packages (filled while updating mirror)
|
||||
@@ -142,6 +155,37 @@ func (repo *RemoteRepo) RefList() *PackageRefList {
|
||||
return repo.packageRefs
|
||||
}
|
||||
|
||||
// MarkAsUpdating puts current PID and sets status to updating
|
||||
func (repo *RemoteRepo) MarkAsUpdating() {
|
||||
repo.Status = MirrorUpdating
|
||||
repo.WorkerPID = os.Getpid()
|
||||
}
|
||||
|
||||
// MarkAsIdle clears updating flag
|
||||
func (repo *RemoteRepo) MarkAsIdle() {
|
||||
repo.Status = MirrorIdle
|
||||
repo.WorkerPID = 0
|
||||
}
|
||||
|
||||
// CheckLock returns error if mirror is being updated by another process
|
||||
func (repo *RemoteRepo) CheckLock() error {
|
||||
if repo.Status == MirrorIdle || repo.WorkerPID == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
p, err := os.FindProcess(repo.WorkerPID)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
err = p.Signal(syscall.Signal(0))
|
||||
if err == nil {
|
||||
return fmt.Errorf("mirror is locked by update operation, PID %d", repo.WorkerPID)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReleaseURL returns URL to Release* files in repo root
|
||||
func (repo *RemoteRepo) ReleaseURL(name string) *url.URL {
|
||||
var path *url.URL
|
||||
@@ -468,13 +512,19 @@ func (repo *RemoteRepo) BuildDownloadQueue(packagePool aptly.PackagePool) (queue
|
||||
return
|
||||
}
|
||||
|
||||
repo.packageRefs = NewPackageRefListFromPackageList(repo.packageList)
|
||||
repo.tempPackageRefs = NewPackageRefListFromPackageList(repo.packageList)
|
||||
// free up package list, we don't need it after this point
|
||||
repo.packageList = nil
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// FinalizeDownload swaps for final value of package refs
|
||||
func (repo *RemoteRepo) FinalizeDownload() {
|
||||
repo.LastDownloadDate = time.Now()
|
||||
repo.packageRefs = repo.tempPackageRefs
|
||||
}
|
||||
|
||||
// Encode does msgpack encoding of RemoteRepo
|
||||
func (repo *RemoteRepo) Encode() []byte {
|
||||
var buf bytes.Buffer
|
||||
|
||||
Reference in New Issue
Block a user