Creates a copy of a specified file in the images dir
()
| 1351 | @APP.route("/files/copy", methods=["POST"]) |
| 1352 | @login_required |
| 1353 | def copy(): |
| 1354 | """ |
| 1355 | Creates a copy of a specified file in the images dir |
| 1356 | """ |
| 1357 | file_name = Path(request.form.get("file_name")) |
| 1358 | new_file_name = Path(request.form.get("copy_file_name")) |
| 1359 | safe_path = is_safe_path(file_name) |
| 1360 | if not safe_path["status"]: |
| 1361 | return response(error=True, message=safe_path["msg"]) |
| 1362 | safe_path = is_safe_path(new_file_name) |
| 1363 | if not safe_path["status"]: |
| 1364 | return response(error=True, message=safe_path["msg"]) |
| 1365 | server_info = piscsi_cmd.get_server_info() |
| 1366 | process = file_cmd.copy_file( |
| 1367 | Path(server_info["image_dir"]) / str(file_name), |
| 1368 | Path(server_info["image_dir"]) / str(new_file_name), |
| 1369 | ) |
| 1370 | process = ReturnCodeMapper.add_msg(process) |
| 1371 | if not process["status"]: |
| 1372 | return response(error=True, message=process["msg"]) |
| 1373 | |
| 1374 | # Create a copy of the drive properties file, if it exists |
| 1375 | prop_file_path = Path(CFG_DIR) / f"{file_name}.{PROPERTIES_SUFFIX}" |
| 1376 | new_prop_file_path = Path(CFG_DIR) / f"{new_file_name}.{PROPERTIES_SUFFIX}" |
| 1377 | if prop_file_path.is_file(): |
| 1378 | process = file_cmd.copy_file(prop_file_path, new_prop_file_path) |
| 1379 | process = ReturnCodeMapper.add_msg(process) |
| 1380 | if process["status"]: |
| 1381 | return response( |
| 1382 | message=_( |
| 1383 | "Copy of image file with properties saved as: %(file_name)s", |
| 1384 | file_name=str(new_file_name), |
| 1385 | ), |
| 1386 | ) |
| 1387 | else: |
| 1388 | return response(error=True, message=process["msg"]) |
| 1389 | |
| 1390 | return response( |
| 1391 | message=_( |
| 1392 | "Copy of image file saved as: %(file_name)s", |
| 1393 | file_name=str(new_file_name), |
| 1394 | ), |
| 1395 | ) |
| 1396 | |
| 1397 | |
| 1398 | @APP.route("/files/extract_image", methods=["POST"]) |
nothing calls this directly
no test coverage detected