github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/imageunpacker/unpacker/removeDevice.go (about)

     1  package unpacker
     2  
     3  import (
     4  	"errors"
     5  )
     6  
     7  func (u *Unpacker) removeDevice(deviceId string) error {
     8  	u.rwMutex.Lock()
     9  	defer u.rwMutex.Unlock()
    10  	defer u.updateUsageTimeWithLock()
    11  	if device, ok := u.pState.Devices[deviceId]; !ok {
    12  		return errors.New("unknown device ID: " + deviceId)
    13  	} else {
    14  		if device.StreamName != "" {
    15  			return errors.New(
    16  				"device ID: " + deviceId + " used by: " + device.StreamName)
    17  		}
    18  		delete(u.pState.Devices, deviceId)
    19  		return u.writeStateWithLock()
    20  	}
    21  }