2021-11-23 05:19:30 +00:00
|
|
|
package blefs
|
|
|
|
|
|
|
|
// Rename moves or renames a file or directory
|
|
|
|
func (blefs *FS) Rename(old, new string) error {
|
|
|
|
// Create move request
|
|
|
|
err := blefs.request(
|
|
|
|
FSCmdMove,
|
|
|
|
true,
|
|
|
|
uint16(len(old)),
|
|
|
|
uint16(len(new)),
|
|
|
|
old,
|
|
|
|
byte(0x00),
|
|
|
|
new,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var status int8
|
|
|
|
// Upon receiving 0x61 (FSResponseMove)
|
|
|
|
blefs.on(FSResponseMove, func(data []byte) error {
|
|
|
|
// Read status byte
|
|
|
|
return decode(data, &status)
|
|
|
|
})
|
|
|
|
// If status is not ok, return error
|
|
|
|
if status != FSStatusOk {
|
|
|
|
return FSError{status}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove removes a file or directory
|
|
|
|
func (blefs *FS) Remove(path string) error {
|
|
|
|
// Create delete request
|
|
|
|
err := blefs.request(
|
|
|
|
FSCmdDelete,
|
|
|
|
true,
|
|
|
|
uint16(len(path)),
|
|
|
|
path,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var status int8
|
|
|
|
// Upon receiving 0x31 (FSResponseDelete)
|
|
|
|
blefs.on(FSResponseDelete, func(data []byte) error {
|
|
|
|
// Read status byte
|
|
|
|
return decode(data, &status)
|
|
|
|
})
|
2022-05-05 19:39:16 +00:00
|
|
|
if status != FSStatusOk {
|
|
|
|
// If status is not ok, return error
|
2021-11-23 05:19:30 +00:00
|
|
|
return FSError{status}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|