Reject duplicate image files (#162)

* Reject duplicate image files

* Renaming
This commit is contained in:
Uwe Seimet 2021-08-06 03:38:03 +02:00 committed by GitHub
parent 8601452b67
commit dd7ce23adc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -63,6 +63,7 @@ int monsocket; // Monitor Socket
pthread_t monthread; // Monitor Thread
pthread_mutex_t ctrl_mutex; // Semaphore for the ctrl array
static void *MonThread(void *param);
set<string> files_in_use;
//---------------------------------------------------------------------------
//
@ -563,6 +564,13 @@ bool ProcessCmd(int fd, const PbCommand &command)
// Strip the image file extension from device file names, so that device files can be used as drive images
string file = params.find("/dev/") ? params : params.substr(0, params.length() - 4);
if (files_in_use.find(file) != files_in_use.end()) {
ostringstream error;
error << "Image file '" << file << "' is already in use";
return ReturnStatus(fd, false, error.str());
}
files_in_use.insert(file);
// Set the Path
filepath.SetPath(file.c_str());
@ -617,6 +625,13 @@ bool ProcessCmd(int fd, const PbCommand &command)
// Re-map the controller
bool status = MapController(map);
if (status) {
Filepath filepath;
pUnit->GetPath(filepath);
files_in_use.erase(filepath.GetPath());
}
return ReturnStatus(fd, status, status ? "" : "Error : SASI and SCSI can't be mixed\n");
}