@@ -331,14 +331,23 @@ APPLICATION_INFO::HandleShadowCopy(const ShimOptions& options, IHttpContext& pHt
331
331
auto shadowCopyBaseDirectory = std::filesystem::directory_entry (shadowCopyPath);
332
332
if (!shadowCopyBaseDirectory.exists ())
333
333
{
334
- LOG_INFOF (L" Attempting to Create Directory" );
335
-
336
334
auto ret = CreateDirectory (shadowCopyBaseDirectory.path ().wstring ().c_str (), nullptr );
337
335
if (!ret)
338
336
{
339
- LOG_ERRORF (L" Failed to create shadow copy base directory %ls. Error: %d" ,
340
- shadowCopyBaseDirectory.path ().c_str (),
341
- GetLastError ());
337
+ auto pathString = to_multi_byte_string (shadowCopyBaseDirectory.path (), CP_UTF8);
338
+ auto errorCode = std::error_code (GetLastError (), std::system_category ());
339
+ std::string errorMessage = format (" Failed to create shadow copy base directory %s. Error: %s" ,
340
+ pathString.c_str (),
341
+ errorCode.message ().c_str ());
342
+
343
+ // TODO: Better substatus code
344
+ error.statusCode = 500i16;
345
+ error.subStatusCode = 30i16;
346
+ error.generalErrorType = format (" ASP.NET Core app failed to start - Failed to copy to shadow copy directory" );
347
+ error.errorReason = format (" Ensure the application pool process model has write permissions for the shadow copy base directory %s" ,
348
+ pathString.c_str ());
349
+ error.detailedErrorContent = errorMessage;
350
+ return std::wstring ();
342
351
}
343
352
}
344
353
@@ -373,7 +382,7 @@ APPLICATION_INFO::HandleShadowCopy(const ShimOptions& options, IHttpContext& pHt
373
382
// It could expand to a network drive, or an expanded link folder path
374
383
// We already made it an absolute path relative to the physicalPath above
375
384
try {
376
- // CopyToDirectory throws exception on failure, therefore don't need to check return value
385
+ // CopyToDirectory will succeed or throw exception, so return value can be ignored
377
386
Environment::CopyToDirectory (physicalPath, shadowCopyPath, options.QueryCleanShadowCopyDirectory (), shadowCopyBaseDirectory.path (), copiedFileCount);
378
387
}
379
388
catch (const std::system_error& ex)
0 commit comments