github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/imageunpacker/rpcd/addDevice.go (about) 1 package rpcd 2 3 import ( 4 "github.com/Cloud-Foundations/Dominator/lib/srpc" 5 ) 6 7 func (t *srpcType) AddDevice(conn *srpc.Conn) error { 8 t.addDeviceLock.Lock() 9 defer t.addDeviceLock.Unlock() 10 if err := t.unpacker.PrepareForAddDevice(); err != nil { 11 _, err = conn.WriteString(err.Error() + "\n") 12 return err 13 } 14 if _, err := conn.WriteString("\n"); err != nil { 15 return err 16 } 17 if err := conn.Flush(); err != nil { 18 return err 19 } 20 deviceId, err := conn.ReadString('\n') 21 if err != nil { 22 return err 23 } 24 deviceId = deviceId[:len(deviceId)-1] 25 if err := t.unpacker.AddDevice(deviceId); err != nil { 26 t.logger.Println(err) 27 _, err = conn.WriteString(err.Error() + "\n") 28 return err 29 } 30 _, err = conn.WriteString("\n") 31 return err 32 }