Sync a declarative package list with the pacman package manager
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

1.2 KiB

Tasks

  • 1. Create state module

Create pkg/state/state.go:

  • OpenLog() - opens /var/log/declpac.log in append mode

  • GetLogWriter() - returns the raw log file writer (for MultiWriter)

  • Write(msg []byte) - writes message with timestamp + dashes separator

  • Close() - closes the file

  • 2. Wire into main.go

In cmd/declpac/main.go run():

  • Call OpenLog() at start

  • defer Close() log

  • 3. Instrument pkg/pacman

Modify pkg/pacman/pacman.go:

All state-modifying functions use state.Write() instead of state.GetLogWriter().Write():

// OLD
state.GetLogWriter().Write(output)

// NEW
state.Write(output)  // auto-prepends timestamp

Functions updated:

  • SyncPackages() - write output with timestamp

  • CleanupOrphans() - write output with timestamp

  • MarkAllAsDeps() - write operation name with timestamp before running

  • MarkAsExplicit() - write operation name with timestamp before running

  • InstallAUR() - write "Cloning ..." and "Building package..." with timestamps

  • Error handling - state.Write([]byte("error: ...")) for all error paths

  • 4. Add io import

Add io to imports in pacman.go

  • 5. Test

Run a sync operation and verify log file created at /var/log/declpac.log