mirror of
https://github.com/akuker/RASCSI.git
synced 2024-12-24 12:30:20 +00:00
Updated error messages
This commit is contained in:
parent
ad0e454e66
commit
fd97650712
@ -725,32 +725,32 @@ bool CreateImage(int fd, const PbCommand& command)
|
|||||||
{
|
{
|
||||||
string filename = GetParam(command, "file");
|
string filename = GetParam(command, "file");
|
||||||
if (filename.empty()) {
|
if (filename.empty()) {
|
||||||
return ReturnStatus(fd, false, "Missing image filename");
|
return ReturnStatus(fd, false, "Can't create image file: Missing image filename");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsValidFilename(filename)) {
|
if (!IsValidFilename(filename)) {
|
||||||
return ReturnStatus(fd, false, "Invalid filename '" + filename + "'");
|
return ReturnStatus(fd, false, "Can't create image file: '" + filename + "': Invalid filename");
|
||||||
}
|
}
|
||||||
|
|
||||||
string size = GetParam(command, "size");
|
string size = GetParam(command, "size");
|
||||||
if (size.empty()) {
|
if (size.empty()) {
|
||||||
return ReturnStatus(fd, false, "Missing image size");
|
return ReturnStatus(fd, false, "Can't create image file '" + filename + "': Missing image size");
|
||||||
}
|
}
|
||||||
|
|
||||||
string permission = GetParam(command, "read_only");
|
string permission = GetParam(command, "read_only");
|
||||||
if (permission.empty()) {
|
if (permission.empty()) {
|
||||||
return ReturnStatus(fd, false, "Missing read-only flag");
|
return ReturnStatus(fd, false, "Can't create image file'" + filename + "': Missing read-only flag");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcasecmp(permission.c_str(), "true") && strcasecmp(permission.c_str(), "false")) {
|
if (strcasecmp(permission.c_str(), "true") && strcasecmp(permission.c_str(), "false")) {
|
||||||
return ReturnStatus(fd, false, "Invalid read-only flag '" + permission + "'");
|
return ReturnStatus(fd, false, "Can't create image file '" + filename + "': Invalid read-only flag '" + permission + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
int permissions = !strcasecmp(permission.c_str(), "true") ?
|
int permissions = !strcasecmp(permission.c_str(), "true") ?
|
||||||
S_IRUSR | S_IRGRP | S_IROTH : S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
|
S_IRUSR | S_IRGRP | S_IROTH : S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
|
||||||
|
|
||||||
if (filename.find('/') != string::npos) {
|
if (filename.find('/') != string::npos) {
|
||||||
return ReturnStatus(fd, false, "The image filename '" + filename + "' must not contain a path");
|
return ReturnStatus(fd, false, "Can't create image file '" + filename + "': Filename must not contain a path");
|
||||||
}
|
}
|
||||||
|
|
||||||
filename = default_image_folder + "/" + filename;
|
filename = default_image_folder + "/" + filename;
|
||||||
@ -760,10 +760,10 @@ bool CreateImage(int fd, const PbCommand& command)
|
|||||||
len = stoul(size);
|
len = stoul(size);
|
||||||
}
|
}
|
||||||
catch(const invalid_argument& e) {
|
catch(const invalid_argument& e) {
|
||||||
return ReturnStatus(fd, false, "Invalid image file size " + size);
|
return ReturnStatus(fd, false, "Can't create image file '" + filename + "': Invalid file size " + size);
|
||||||
}
|
}
|
||||||
catch(const out_of_range& e) {
|
catch(const out_of_range& e) {
|
||||||
return ReturnStatus(fd, false, "Invalid image file size " + size);
|
return ReturnStatus(fd, false, "Can't create image file '" + filename + "': Invalid file size " + size);
|
||||||
}
|
}
|
||||||
if (len < 512 || (len & 0x1ff)) {
|
if (len < 512 || (len & 0x1ff)) {
|
||||||
ostringstream error;
|
ostringstream error;
|
||||||
@ -773,7 +773,7 @@ bool CreateImage(int fd, const PbCommand& command)
|
|||||||
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (!stat(filename.c_str(), &st)) {
|
if (!stat(filename.c_str(), &st)) {
|
||||||
return ReturnStatus(fd, false, "Image file '" + filename + "' already exists");
|
return ReturnStatus(fd, false, "Can't create image file '" + filename + "': File already exists");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since rascsi is running as root ensure that others can access the file
|
// Since rascsi is running as root ensure that others can access the file
|
||||||
@ -805,7 +805,7 @@ bool DeleteImage(int fd, const PbCommand& command)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!IsValidFilename(filename)) {
|
if (!IsValidFilename(filename)) {
|
||||||
return ReturnStatus(fd, false, "Invalid filename '" + filename + "'");
|
return ReturnStatus(fd, false, "Can't delete image file '" + filename + "': Invalid filename");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filename.find('/') != string::npos) {
|
if (filename.find('/') != string::npos) {
|
||||||
@ -837,20 +837,20 @@ bool RenameImage(int fd, const PbCommand& command)
|
|||||||
{
|
{
|
||||||
string from = GetParam(command, "from");
|
string from = GetParam(command, "from");
|
||||||
if (from.empty()) {
|
if (from.empty()) {
|
||||||
return ReturnStatus(fd, false, "Missing source filename");
|
return ReturnStatus(fd, false, "Can't rename image file: Missing source filename");
|
||||||
}
|
}
|
||||||
|
|
||||||
string to = GetParam(command, "to");
|
string to = GetParam(command, "to");
|
||||||
if (to.empty()) {
|
if (to.empty()) {
|
||||||
return ReturnStatus(fd, false, "Missing destination filename");
|
return ReturnStatus(fd, false, "Can't rename image file '" + from + "': Missing destination filename");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsValidFilename(from)) {
|
if (!IsValidFilename(from)) {
|
||||||
return ReturnStatus(fd, false, "Invalid filename '" + from + "'");
|
return ReturnStatus(fd, false, "Can't rename image file: '" + from + "': Invalid filename");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsValidFilename(to)) {
|
if (!IsValidFilename(to)) {
|
||||||
return ReturnStatus(fd, false, "Invalid filename '" + to + "'");
|
return ReturnStatus(fd, false, "Can't rename image file '" + from + "' to '" + to + "': Invalid filename");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (from.find('/') != string::npos) {
|
if (from.find('/') != string::npos) {
|
||||||
@ -881,20 +881,20 @@ bool CopyImage(int fd, const PbCommand& command)
|
|||||||
{
|
{
|
||||||
string from = GetParam(command, "from");
|
string from = GetParam(command, "from");
|
||||||
if (from.empty()) {
|
if (from.empty()) {
|
||||||
return ReturnStatus(fd, false, "Missing source filename");
|
return ReturnStatus(fd, false, "Can't copy image file: Missing source filename");
|
||||||
}
|
}
|
||||||
|
|
||||||
string to = GetParam(command, "to");
|
string to = GetParam(command, "to");
|
||||||
if (to.empty()) {
|
if (to.empty()) {
|
||||||
return ReturnStatus(fd, false, "Missing destination filename");
|
return ReturnStatus(fd, false, "Can't copy image file '" + from + "': Missing destination filename");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsValidFilename(from)) {
|
if (!IsValidFilename(from)) {
|
||||||
return ReturnStatus(fd, false, "Invalid filename '" + from + "'");
|
return ReturnStatus(fd, false, "Can't copy image file: '" + from + "': Invalid filename");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsValidFilename(to)) {
|
if (!IsValidFilename(to)) {
|
||||||
return ReturnStatus(fd, false, "Invalid filename '" + to + "'");
|
return ReturnStatus(fd, false, "Can't copy image file '" + from + "' to '" + to + "': Invalid filename");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (from.find('/') != string::npos) {
|
if (from.find('/') != string::npos) {
|
||||||
@ -952,7 +952,7 @@ bool SetImagePermissions(int fd, const PbCommand& command)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!IsValidFilename(filename)) {
|
if (!IsValidFilename(filename)) {
|
||||||
return ReturnStatus(fd, false, "Invalid filename '" + filename + "'");
|
return ReturnStatus(fd, false, "Can't modify image file '" + filename + "': Invalid filename");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filename.find('/') != string::npos) {
|
if (filename.find('/') != string::npos) {
|
||||||
|
Loading…
Reference in New Issue
Block a user