mirror of
https://github.com/akuker/RASCSI.git
synced 2024-12-30 05:29:47 +00:00
Added RENAME_IMAGE
This commit is contained in:
parent
492f332dd7
commit
434ea0e3f7
@ -40,6 +40,9 @@ The rascsi host to connect to, default is 'localhost'.
|
||||
.BR \-l\fI
|
||||
List all of the devices that are currently being emulated by RaSCSI, as well as their current status.
|
||||
.TP
|
||||
.BR \-m\fI " "\fIOLD_NAME:NEW_NAME
|
||||
Rename an image file in the default image folder.
|
||||
.TP
|
||||
.BR \-p\fI " " \fIPORT
|
||||
The rascsi port to connect to, default is 6868.
|
||||
.TP
|
||||
|
@ -35,6 +35,9 @@ OPTIONS
|
||||
-l List all of the devices that are currently being emulated by
|
||||
RaSCSI, as well as their current status.
|
||||
|
||||
-m OLD_NAME:NEW_NAME
|
||||
Rename an image file in the default image folder.
|
||||
|
||||
-p PORT
|
||||
The rascsi port to connect to, default is 6868.
|
||||
|
||||
|
@ -776,6 +776,31 @@ bool DeleteImage(int fd, const PbCommand& command)
|
||||
return ReturnStatus(fd);
|
||||
}
|
||||
|
||||
bool RenameImage(int fd, const PbCommand& command)
|
||||
{
|
||||
if (command.params().size() < 2 || command.params().Get(0).empty() || command.params().Get(1).empty()) {
|
||||
return ReturnStatus(fd, false, "Can't rename image file: Missing filename");
|
||||
}
|
||||
|
||||
string src = command.params().Get(0);
|
||||
if (src.find('/') != string::npos) {
|
||||
return ReturnStatus(fd, false, "The image filename '" + src + "' must not contain a path");
|
||||
}
|
||||
string dst = command.params().Get(1);
|
||||
if (dst.find('/') != string::npos) {
|
||||
return ReturnStatus(fd, false, "The image filename '" + dst + "' must not contain a path");
|
||||
}
|
||||
|
||||
src = default_image_folder + "/" + src;
|
||||
dst = default_image_folder + "/" + dst;
|
||||
|
||||
if (rename(src.c_str(), dst.c_str())) {
|
||||
return ReturnStatus(fd, false, "Can't rename image file '" + src + "' to '" + dst + "': " + string(strerror(errno)));
|
||||
}
|
||||
|
||||
return ReturnStatus(fd);
|
||||
}
|
||||
|
||||
void DetachAll()
|
||||
{
|
||||
Device *map[devices.size()];
|
||||
@ -1230,6 +1255,9 @@ bool ProcessCmd(const int fd, const PbCommand& command)
|
||||
case DELETE_IMAGE:
|
||||
return DeleteImage(fd, command);
|
||||
|
||||
case RENAME_IMAGE:
|
||||
return RenameImage(fd, command);
|
||||
|
||||
default:
|
||||
// This is a device-specific command handled below
|
||||
break;
|
||||
|
@ -66,9 +66,12 @@ enum PbOperation {
|
||||
// Delete an image file. PbCommand.params(0) contains the filename.
|
||||
// The filename is relative to the default image folder and must not contain a slash.
|
||||
DELETE_IMAGE = 16;
|
||||
// Rename an image file. PbCommand.params(0) contains the old filename, PbCommand.params(1) the new name.
|
||||
// The filename is relative to the default image folder and must not contain a slash.
|
||||
RENAME_IMAGE = 17;
|
||||
}
|
||||
|
||||
// The properties supported by a device, helping clients to offer a good user experience
|
||||
// The properties supported by a device
|
||||
message PbDeviceProperties {
|
||||
// Read-only media (e.g. CD-ROMs) are not protectable but permanently read-only
|
||||
bool read_only = 1;
|
||||
|
@ -232,6 +232,21 @@ void CommandDeleteImage(const string&hostname, int port, const string& filename)
|
||||
SendCommand(hostname.c_str(), port, command, result);
|
||||
}
|
||||
|
||||
void CommandRenameImage(const string&hostname, int port, const string& image_params)
|
||||
{
|
||||
PbCommand command;
|
||||
command.set_operation(RENAME_IMAGE);
|
||||
|
||||
size_t separatorPos = image_params.find(COMPONENT_SEPARATOR);
|
||||
if (separatorPos != string::npos) {
|
||||
command.add_params(image_params.substr(0, separatorPos));
|
||||
command.add_params(image_params.substr(separatorPos + 1));
|
||||
}
|
||||
|
||||
PbResult result;
|
||||
SendCommand(hostname.c_str(), port, command, result);
|
||||
}
|
||||
|
||||
void CommandDefaultImageFolder(const string& hostname, int port, const string& folder)
|
||||
{
|
||||
PbCommand command;
|
||||
@ -533,7 +548,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
opterr = 1;
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "a:b:c:d:f:g:h:i:n:p:r:t:u:x:lsv")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "a:b:c:d:f:g:h:i:m:n:p:r:t:u:x:lsv")) != -1) {
|
||||
switch (opt) {
|
||||
case 'i':
|
||||
device->set_id(optarg[0] - '0');
|
||||
@ -595,6 +610,11 @@ int main(int argc, char* argv[])
|
||||
list = true;
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
command.set_operation(RENAME_IMAGE);
|
||||
image_params = optarg;
|
||||
break;
|
||||
|
||||
case 'n': {
|
||||
string vendor;
|
||||
string product;
|
||||
@ -677,6 +697,10 @@ int main(int argc, char* argv[])
|
||||
CommandDeleteImage(hostname, port, image_params);
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
case RENAME_IMAGE:
|
||||
CommandRenameImage(hostname, port, image_params);
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
case DEVICE_INFO:
|
||||
CommandDeviceInfo(hostname, port, command);
|
||||
exit(EXIT_SUCCESS);
|
||||
|
Loading…
Reference in New Issue
Block a user