@@ -159,9 +159,10 @@ type Config struct {
159159// NewFSManager creates a new Manager instance for ZFS.
160160func NewFSManager (runner runners.Runner , config Config ) * Manager {
161161 m := Manager {
162- runner : runner ,
163- config : config ,
164- mu : & sync.Mutex {},
162+ runner : runner ,
163+ config : config ,
164+ mu : & sync.Mutex {},
165+ snapshots : make ([]resources.Snapshot , 0 ),
165166 }
166167
167168 return & m
@@ -172,6 +173,11 @@ func (m *Manager) Pool() *resources.Pool {
172173 return m .config .Pool
173174}
174175
176+ // UpdateConfig updates the manager's configuration.
177+ func (m * Manager ) UpdateConfig (cfg Config ) {
178+ m .config = cfg
179+ }
180+
175181// CreateClone creates a new ZFS clone.
176182func (m * Manager ) CreateClone (cloneName , snapshotID string ) error {
177183 exists , err := m .cloneExists (cloneName )
@@ -316,14 +322,20 @@ func (m *Manager) CreateSnapshot(poolSuffix, dataStateAt string) (string, error)
316322 return "" , fmt .Errorf ("failed to parse dataStateAt: %w" , err )
317323 }
318324
319- m . addSnapshotToList ( resources.Snapshot {
325+ newSnapshot := resources.Snapshot {
320326 ID : snapshotName ,
321327 CreatedAt : time .Now (),
322328 DataStateAt : dataStateTime ,
323329 Pool : m .config .Pool .Name ,
324- })
330+ }
331+
332+ if ! strings .HasSuffix (snapshotName , m .config .PreSnapshotSuffix ) {
333+ m .addSnapshotToList (newSnapshot )
325334
326- go m .RefreshSnapshotList ()
335+ log .Dbg ("New snapshot:" , newSnapshot )
336+
337+ m .RefreshSnapshotList ()
338+ }
327339
328340 return snapshotName , nil
329341}
@@ -511,8 +523,11 @@ func (m *Manager) GetFilesystemState() (models.FileSystem, error) {
511523
512524// SnapshotList returns a list of snapshots.
513525func (m * Manager ) SnapshotList () []resources.Snapshot {
514- snapshotList := m .snapshots
515- return snapshotList
526+ m .mu .Lock ()
527+ snapshots := m .snapshots
528+ m .mu .Unlock ()
529+
530+ return snapshots
516531}
517532
518533// RefreshSnapshotList updates the list of snapshots.
@@ -559,20 +574,22 @@ func (m *Manager) getSnapshots() ([]resources.Snapshot, error) {
559574
560575func (m * Manager ) addSnapshotToList (snapshot resources.Snapshot ) {
561576 m .mu .Lock ()
562- m .snapshots = append (m . snapshots , snapshot )
577+ m .snapshots = append ([]resources. Snapshot { snapshot }, m . snapshots ... )
563578 m .mu .Unlock ()
564579}
565580
566581func (m * Manager ) removeSnapshotFromList (snapshotName string ) {
582+ m .mu .Lock ()
583+
567584 for i , snapshot := range m .snapshots {
568585 if snapshot .ID == snapshotName {
569- m .mu .Lock ()
570- m .snapshots = append (m .snapshots [:i ], m .snapshots [i + 1 :]... )
571- m .mu .Unlock ()
586+ m .snapshots = append ((m .snapshots )[:i ], (m .snapshots )[i + 1 :]... )
572587
573588 break
574589 }
575590 }
591+
592+ m .mu .Unlock ()
576593}
577594
578595// ListFilesystems lists ZFS file systems (clones, pools).
0 commit comments