// Put updates the StorageConfig tracking state for a Cid.
// If the StorageConfig is repairable or renewable, it will be
// added (or updated if exist) for a Cid. If it isn't repairable
// or renewable, it will ensure it's removed from the store
// if exists. This last point happens when a StorageConfig
// which was repairable/renewable get that feature disabled.
Put updates the StorageConfig tracking state for a Cid.
If the StorageConfig is repairable or renewable, it will be
added (or updated if exist) for a Cid. If it isn't repairable
or renewable, it will ensure it's removed from the store
if exists. This last point happens when a StorageConfig
which was repairable/renewable get that feature disabled.
// Put updates the StorageConfig tracking state for a Cid . // If the StorageConfig is repairable or renewable it will be // added ( or updated if exist ) for a Cid . If it isn ' t repairable // or renewable it will ensure it ' s removed from the store // if exists . This last point happens when a StorageConfig // which was repairable / renewable get that feature disabled .
func (s *Store) Put(iid ffs.APIID, c cid.Cid, sc ffs.StorageConfig) error {
	s.lock.Lock()
	defer s.lock.Unlock()
	scs, err := s.get(c)
	if err != nil {
		return fmt.Errorf("getting current storage configs for cid: %s", err)
	}
	idx := -1
	for i := range scs {
		if scs[i].IID == iid {
			idx = i
			break
		}
	}
	isRepairable := sc.Repairable
	isRenewable := sc.Cold.Enabled && sc.Cold.Filecoin.Renew.Enabled
	if isRepairable || isRenewable {
		if idx == -1 {
			nsc := TrackedStorageConfig{IID: iid, StorageConfig: sc}
			scs = append(scs, nsc)
		} else {
			scs[idx].StorageConfig = sc
		}
	} else { 
		if idx != -1 {
			scs[idx] = scs[len(scs)-1]
			scs = scs[:len(scs)-1]
		} else {
			return nil
		}
	}
	if err := s.persist(c, scs); err != nil {
		return fmt.Errorf("persisting updated storage configs for cid: %s", err)
	}
	return nil
}
func ( s * Store ) Put ( iid ffs . APIID , c cid . Cid , sc ffs . StorageConfig ) error { s . lock . Lock ( ) defer s . lock . Unlock ( ) scs , err := s . get ( c ) if err != nil { return fmt . Errorf ( " " , err ) } idx := - 1 for i := range scs { if scs [ i ] . IID == iid { idx = i break } } isRepairable := sc . Repairable isRenewable := sc . Cold . Enabled && sc . Cold . Filecoin . Renew . Enabled if isRepairable || isRenewable { if idx == - 1 { nsc := TrackedStorageConfig { IID : iid , StorageConfig : sc } scs = append ( scs , nsc ) } else { scs [ idx ] . StorageConfig = sc } } else { if idx != - 1 { scs [ idx ] = scs [ len ( scs ) - 1 ] scs = scs [ : len ( scs ) - 1 ] } else { return nil } } if err := s . persist ( c , scs ) ; err != nil { return fmt . Errorf ( " " , err ) } return nil }
Put updates the StorageConfig tracking state for a Cid.
Put updates the StorageConfig tracking state for a Cid .
// If has any of the interesting features, it should be in the slice. // Not interesting storage config to track, remove if present or simply return.