| 16 | } |
| 17 | |
| 18 | Value FileSystemFactory::loadModule() { |
| 19 | Value out; |
| 20 | |
| 21 | auto strongThis = shared_from_this(); |
| 22 | |
| 23 | out.setMapValue( |
| 24 | "removeSync", |
| 25 | Value(makeShared<ValueFunctionWithCallable>([strongThis](const ValueFunctionCallContext& callContext) -> Value { |
| 26 | auto pathNameResult = callContext.getParameterAsString(0); |
| 27 | |
| 28 | if (!callContext.getExceptionTracker()) { |
| 29 | return Value::undefined(); |
| 30 | } |
| 31 | |
| 32 | Path const path = Path(pathNameResult.toStringView()); |
| 33 | |
| 34 | bool const result = DiskUtils::remove(path); |
| 35 | if (!result) { |
| 36 | callContext.getExceptionTracker().onError(fmt::format("Could not remove path: '{}'", pathNameResult)); |
| 37 | return Value::undefined(); |
| 38 | } |
| 39 | |
| 40 | return Value(result); |
| 41 | }))); |
| 42 | |
| 43 | out.setMapValue( |
| 44 | "createDirectorySync", |
| 45 | Value(makeShared<ValueFunctionWithCallable>([strongThis](const ValueFunctionCallContext& callContext) -> Value { |
| 46 | auto pathName = callContext.getParameterAsString(0); |
| 47 | |
| 48 | if (!callContext.getExceptionTracker()) { |
| 49 | return Value::undefined(); |
| 50 | } |
| 51 | |
| 52 | auto createIntermediates = callContext.getParameterAsBool(1); |
| 53 | if (!callContext.getExceptionTracker()) { |
| 54 | callContext.getExceptionTracker().onError( |
| 55 | fmt::format("Please set createIntermediates for: '{}'", pathName)); |
| 56 | return Value::undefined(); |
| 57 | } |
| 58 | |
| 59 | Path const path = Path(pathName.toStringView()); |
| 60 | |
| 61 | bool const result = DiskUtils::makeDirectory(path, createIntermediates); |
| 62 | if (!result) { |
| 63 | callContext.getExceptionTracker().onError( |
| 64 | fmt::format("Could not create directory at path: '{}'", pathName)); |
| 65 | return Value::undefined(); |
| 66 | } |
| 67 | |
| 68 | return Value(result); |
| 69 | }))); |
| 70 | |
| 71 | out.setMapValue( |
| 72 | "readFileSync", |
| 73 | Value(makeShared<ValueFunctionWithCallable>([strongThis](const ValueFunctionCallContext& callContext) -> Value { |
| 74 | auto pathToFile = callContext.getParameterAsString(0); |
| 75 |
nothing calls this directly
no test coverage detected