mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-09 01:12:29 +02:00
Update PR
* Update when an API instance is released and when it is destroyed * Add logging to determine curl pool usage
This commit is contained in:
parent
0dd936be3d
commit
a8ed848abd
|
@ -13,6 +13,9 @@ import std.range;
|
|||
|
||||
// What other modules that we have created do we need to import?
|
||||
import log;
|
||||
import util;
|
||||
|
||||
__gshared CurlEngine[] curlEnginePool;
|
||||
|
||||
class CurlResponse {
|
||||
HTTP.Method method;
|
||||
|
@ -160,52 +163,64 @@ class CurlResponse {
|
|||
|
||||
class CurlEngine {
|
||||
|
||||
__gshared static CurlEngine[] curlEnginePool; // __gshared is used for thread-shared static variables
|
||||
|
||||
HTTP http;
|
||||
bool keepAlive;
|
||||
ulong dnsTimeout;
|
||||
CurlResponse response;
|
||||
File uploadFile;
|
||||
string internalThreadId;
|
||||
|
||||
this() {
|
||||
this.http = HTTP(); // Directly initializes HTTP using its default constructor
|
||||
this.response = null; // Initialize as null
|
||||
http = HTTP(); // Directly initializes HTTP using its default constructor
|
||||
response = null; // Initialize as null
|
||||
internalThreadId = generateAlphanumericString();
|
||||
}
|
||||
|
||||
~this() {
|
||||
~this() {
|
||||
// The destructor should only clean up resources owned directly by this instance
|
||||
addLogEntry("CurlEngine DESTRUCTOR CALLED", ["debug"]);
|
||||
|
||||
// Avoid modifying or destroying shared/static resources here
|
||||
if (uploadFile.isOpen()) {
|
||||
uploadFile.close();
|
||||
}
|
||||
|
||||
// Cleanup class memory usage
|
||||
object.destroy(this.uploadFile); // Destroy, however we cant set to null
|
||||
object.destroy(this.response); // Destroy, then set to null
|
||||
this.response = null;
|
||||
object.destroy(uploadFile); // Destroy, however we cant set to null
|
||||
object.destroy(response); // Destroy, then set to null
|
||||
response = null;
|
||||
internalThreadId = null;
|
||||
|
||||
// Is the http instance is stopped?
|
||||
if (!this.http.isStopped) {
|
||||
this.http.shutdown();
|
||||
// Is the actual http instance is stopped?
|
||||
if (!http.isStopped) {
|
||||
// instance was not stopped .. need to stop it
|
||||
addLogEntry("CurlEngine DESTRUCTOR HTTP INSTANCE WAS NOT STOPPED - STOPPING", ["debug"]);
|
||||
http.shutdown();
|
||||
}
|
||||
object.destroy(this.http); // Destroy, however we cant set to null
|
||||
object.destroy(http); // Destroy, however we cant set to null
|
||||
}
|
||||
|
||||
|
||||
static CurlEngine getCurlInstance() {
|
||||
synchronized (CurlEngine.classinfo) {
|
||||
// What is the current pool size
|
||||
addLogEntry("CURL ENGINE AVAILABLE POOL SIZE: " ~ to!string(curlEnginePool.length), ["debug"]);
|
||||
|
||||
if (curlEnginePool.empty) {
|
||||
addLogEntry("CURL ENGINE POOL EMPTY - CONSTRUCTING A NEW CURL ENGINE INSTANCE" , ["debug"]);
|
||||
return new CurlEngine; // Constructs a new CurlEngine with a fresh HTTP instance
|
||||
} else {
|
||||
CurlEngine curlEngine = curlEnginePool[$ - 1];
|
||||
curlEnginePool = curlEnginePool[0 .. $ - 1];
|
||||
curlEnginePool.popBack();
|
||||
|
||||
// Is this engine stopped?
|
||||
if (curlEngine.http.isStopped) {
|
||||
// return a new curl engine as a stopped one cannot be used
|
||||
addLogEntry("CURL ENGINE WAS STOPPED - CONSTRUCTING A NEW CURL ENGINE INSTANCE" , ["debug"]);
|
||||
return new CurlEngine; // Constructs a new CurlEngine with a fresh HTTP instance
|
||||
} else {
|
||||
// return an existing curl engine
|
||||
addLogEntry("CURL ENGINE WAS VALID - RETURNED AN EXISTING CURL ENGINE INSTANCE" , ["debug"]);
|
||||
addLogEntry("CURL ENGINE ID: " ~ curlEngine.internalThreadId, ["debug"]);
|
||||
return curlEngine;
|
||||
}
|
||||
}
|
||||
|
@ -214,39 +229,52 @@ class CurlEngine {
|
|||
|
||||
static void releaseAllCurlInstances() {
|
||||
synchronized (CurlEngine.classinfo) {
|
||||
// What is the current pool size
|
||||
addLogEntry("CURL ENGINES TO RELEASE: " ~ to!string(curlEnginePool.length), ["debug"]);
|
||||
|
||||
// Safely iterate and clean up each CurlEngine instance
|
||||
foreach (CurlEngine curlEngine; curlEnginePool) {
|
||||
foreach (curlEngineInstance; curlEnginePool) {
|
||||
try {
|
||||
curlEngine.cleanup(); // Cleanup instance by resetting values
|
||||
curlEngine.shutdown(); // Assume proper cleanup of any resources used by HTTP
|
||||
curlEngineInstance.cleanup(); // Cleanup instance by resetting values
|
||||
curlEngineInstance.shutdownCurlHTTPInstance(); // Assume proper cleanup of any resources used by HTTP
|
||||
} catch (Exception e) {
|
||||
// Log the error or handle it appropriately
|
||||
// e.g., writeln("Error during cleanup/shutdown: ", e.toString());
|
||||
}
|
||||
// It's safe to destroy the object here assuming no other references exist
|
||||
object.destroy(curlEngine); // Destroy, then set to null
|
||||
curlEngine = null;
|
||||
object.destroy(curlEngineInstance); // Destroy, then set to null
|
||||
curlEngineInstance = null;
|
||||
}
|
||||
// Clear the array after all instances have been handled
|
||||
curlEnginePool.length = 0; // More explicit than curlEnginePool = [];
|
||||
}
|
||||
}
|
||||
|
||||
static void destroyAllCurlInstances() {
|
||||
// Release all 'curl' instances
|
||||
// Destroy all curl instances
|
||||
static void destroyAllCurlInstances() {
|
||||
|
||||
addLogEntry("DESTROY ALL CURL ENGINES", ["debug"]);
|
||||
// Release all 'curl' instances
|
||||
releaseAllCurlInstances();
|
||||
// Destroy curlEnginePool, set to null
|
||||
object.destroy(curlEnginePool);
|
||||
curlEnginePool = null;
|
||||
}
|
||||
|
||||
void release() {
|
||||
cleanup();
|
||||
// We are releasing a curl instance back to the pool
|
||||
void releaseEngine() {
|
||||
addLogEntry("CurlEngine releaseEngine() CALLED", ["debug"]);
|
||||
addLogEntry("CurlEngine releaseEngine() CALLED");
|
||||
addLogEntry("CURRENT CURL ENGINE AVAILABLE POOL SIZE: " ~ to!string(curlEnginePool.length), ["debug"]);
|
||||
addLogEntry("CURRENT CURL ENGINE AVAILABLE POOL SIZE: " ~ to!string(curlEnginePool.length));
|
||||
cleanup();
|
||||
synchronized (CurlEngine.classinfo) {
|
||||
curlEnginePool ~= this;
|
||||
addLogEntry("CURL ENGINE POOL SIZE AFTER RELEASE BACK TO POOL: " ~ to!string(curlEnginePool.length), ["debug"]);
|
||||
addLogEntry("CURL ENGINE POOL SIZE AFTER RELEASE BACK TO POOL: " ~ to!string(curlEnginePool.length));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void initialise(ulong dnsTimeout, ulong connectTimeout, ulong dataTimeout, ulong operationTimeout, int maxRedirects, bool httpsDebug, string userAgent, bool httpProtocol, ulong userRateLimit, ulong protocolVersion, bool keepAlive=true) {
|
||||
// Setting this to false ensures that when we close the curl instance, any open sockets are closed - which we need to do when running
|
||||
// multiple threads and API instances at the same time otherwise we run out of local files | sockets pretty quickly
|
||||
|
@ -440,6 +468,7 @@ class CurlEngine {
|
|||
|
||||
void cleanup() {
|
||||
// Reset any values to defaults, freeing any set objects
|
||||
addLogEntry("CurlEngine cleanup() CALLED", ["debug"]);
|
||||
|
||||
// Is the instance is stopped?
|
||||
if (!http.isStopped) {
|
||||
|
@ -468,8 +497,10 @@ class CurlEngine {
|
|||
}
|
||||
}
|
||||
|
||||
void shutdown() {
|
||||
void shutdownCurlHTTPInstance() {
|
||||
// Shut down the curl instance & close any open sockets
|
||||
addLogEntry("HTTP SHUTDOWN CALLED ..." , ["debug"]);
|
||||
|
||||
// Is the instance is stopped?
|
||||
if (!http.isStopped) {
|
||||
http.shutdown();
|
||||
|
|
|
@ -434,9 +434,9 @@ int main(string[] cliArgs) {
|
|||
|
||||
// Flag that we were able to initalise the API in the application config
|
||||
oneDriveApiInstance.debugOutputConfiguredAPIItems();
|
||||
|
||||
oneDriveApiInstance.shutdown();
|
||||
object.destroy(oneDriveApiInstance);
|
||||
oneDriveApiInstance.releaseCurlEngine();
|
||||
|
||||
//object.destroy(oneDriveApiInstance);
|
||||
|
||||
// Need to configure the itemDB and syncEngineInstance for 'sync' and 'non-sync' operations
|
||||
addLogEntry("Opening the item database ...", ["verbose"]);
|
||||
|
|
|
@ -355,7 +355,7 @@ class OneDriveApi {
|
|||
|
||||
// Reinitialise the OneDrive API class
|
||||
bool reinitialise() {
|
||||
shutdown();
|
||||
releaseCurlEngine();
|
||||
return initialise(this.keepAlive);
|
||||
}
|
||||
|
||||
|
@ -383,11 +383,13 @@ class OneDriveApi {
|
|||
addLogEntry("Configured siteDriveUrl: " ~ siteDriveUrl, ["debug"]);
|
||||
}
|
||||
|
||||
// Shutdown OneDrive API Curl Engine
|
||||
void shutdown() {
|
||||
// Release curl instance
|
||||
// Release CurlEngine bask to the Curl Engine Pool
|
||||
void releaseCurlEngine() {
|
||||
// Log that this was called
|
||||
addLogEntry("OneDrive API releaseCurlEngine() CALLED", ["debug"]);
|
||||
// Release curl instance back to the pool
|
||||
if (curlEngine !is null) {
|
||||
curlEngine.release();
|
||||
curlEngine.releaseEngine();
|
||||
curlEngine = null;
|
||||
}
|
||||
}
|
||||
|
@ -833,7 +835,7 @@ class OneDriveApi {
|
|||
addLogEntry("Please login to https://account.live.com/consent/Manage and remove your existing application access consent");
|
||||
addLogEntry();
|
||||
// force exit
|
||||
shutdown();
|
||||
releaseCurlEngine();
|
||||
// Must force exit here, allow logging to be done
|
||||
forceExit();
|
||||
}
|
||||
|
@ -1136,10 +1138,8 @@ class OneDriveApi {
|
|||
SysTime retryTime;
|
||||
bool retrySuccess = false;
|
||||
bool transientError = false;
|
||||
auto internalThreadId = generateAlphanumericString();
|
||||
|
||||
while (!retrySuccess) {
|
||||
|
||||
while (!retrySuccess) {
|
||||
// Reset thisBackOffInterval
|
||||
thisBackOffInterval = 0;
|
||||
transientError = false;
|
||||
|
@ -1336,9 +1336,9 @@ class OneDriveApi {
|
|||
case 408,429:
|
||||
// If OneDrive sends a status code 429 then this function will be used to process the Retry-After response header which contains the value by which we need to wait
|
||||
if (exception.httpStatusCode == 408) {
|
||||
addLogEntry("Handling a OneDrive HTTP 408 Response Code (Request Time Out) - Internal Thread ID: " ~ to!string(internalThreadId));
|
||||
addLogEntry("Handling a OneDrive HTTP 408 Response Code (Request Time Out) - Internal Thread ID: " ~ to!string(curlEngine.internalThreadId));
|
||||
} else {
|
||||
addLogEntry("Handling a OneDrive HTTP 429 Response Code (Too Many Requests) - Internal Thread ID: " ~ to!string(internalThreadId));
|
||||
addLogEntry("Handling a OneDrive HTTP 429 Response Code (Too Many Requests) - Internal Thread ID: " ~ to!string(curlEngine.internalThreadId));
|
||||
}
|
||||
// Read in the Retry-After HTTP header as set and delay as per this value before retrying the request
|
||||
thisBackOffInterval = response.getRetryAfterValue();
|
||||
|
@ -1352,7 +1352,7 @@ class OneDriveApi {
|
|||
case 503,504:
|
||||
// The server, while acting as a proxy, did not receive a timely response from the upstream server it needed to access in attempting to complete the request
|
||||
auto errorArray = splitLines(exception.msg);
|
||||
addLogEntry(to!string(errorArray[0]) ~ " when attempting to query the OneDrive API Service - retrying applicable request in 30 seconds - Internal Thread ID: " ~ to!string(internalThreadId));
|
||||
addLogEntry(to!string(errorArray[0]) ~ " when attempting to query the OneDrive API Service - retrying applicable request in 30 seconds - Internal Thread ID: " ~ to!string(curlEngine.internalThreadId));
|
||||
addLogEntry("Thread sleeping for 30 seconds as the server did not receive a timely response from the upstream server it needed to access in attempting to complete the request", ["debug"]);
|
||||
// Transient error - try again in 30 seconds
|
||||
thisBackOffInterval = 30;
|
||||
|
@ -1390,7 +1390,7 @@ class OneDriveApi {
|
|||
currentTime = Clock.currTime();
|
||||
currentTime.fracSecs = Duration.zero;
|
||||
auto timeString = currentTime.toString();
|
||||
addLogEntry("Retry attempt: " ~ to!string(retryAttempts) ~ " - Internal Thread ID: " ~ to!string(internalThreadId), ["verbose"]);
|
||||
addLogEntry("Retry attempt: " ~ to!string(retryAttempts) ~ " - Internal Thread ID: " ~ to!string(curlEngine.internalThreadId), ["verbose"]);
|
||||
addLogEntry(" This attempt timestamp: " ~ timeString, ["verbose"]);
|
||||
// Detail when the next attempt will be tried
|
||||
// Factor in the delay for curl to generate the exception - otherwise the next timestamp appears to be 'out' even though technically correct
|
||||
|
|
351
src/sync.d
351
src/sync.d
|
@ -332,10 +332,10 @@ class SyncEngine {
|
|||
// details could not be queried
|
||||
addLogEntry(exception.msg);
|
||||
// Shutdown this API instance, as we will create API instances as required, when required
|
||||
oneDriveApiInstance.shutdown();
|
||||
oneDriveApiInstance.releaseCurlEngine();
|
||||
// Free object and memory
|
||||
object.destroy(oneDriveApiInstance);
|
||||
oneDriveApiInstance = null;
|
||||
//object.destroy(oneDriveApiInstance);
|
||||
//oneDriveApiInstance = null;
|
||||
// Must force exit here, allow logging to be done
|
||||
forceExit();
|
||||
}
|
||||
|
@ -347,10 +347,10 @@ class SyncEngine {
|
|||
// details could not be queried
|
||||
addLogEntry(exception.msg);
|
||||
// Shutdown this API instance, as we will create API instances as required, when required
|
||||
oneDriveApiInstance.shutdown();
|
||||
oneDriveApiInstance.releaseCurlEngine();
|
||||
// Free object and memory
|
||||
object.destroy(oneDriveApiInstance);
|
||||
oneDriveApiInstance = null;
|
||||
//object.destroy(oneDriveApiInstance);
|
||||
//oneDriveApiInstance = null;
|
||||
// Must force exit here, allow logging to be done
|
||||
forceExit();
|
||||
}
|
||||
|
@ -362,10 +362,10 @@ class SyncEngine {
|
|||
// Details could not be queried
|
||||
addLogEntry(exception.msg);
|
||||
// Shutdown this API instance, as we will create API instances as required, when required
|
||||
oneDriveApiInstance.shutdown();
|
||||
oneDriveApiInstance.releaseCurlEngine();
|
||||
// Free object and memory
|
||||
object.destroy(oneDriveApiInstance);
|
||||
oneDriveApiInstance = null;
|
||||
//object.destroy(oneDriveApiInstance);
|
||||
//oneDriveApiInstance = null;
|
||||
// Must force exit here, allow logging to be done
|
||||
forceExit();
|
||||
}
|
||||
|
@ -373,10 +373,10 @@ class SyncEngine {
|
|||
// API could not be initialised
|
||||
addLogEntry("OneDrive API could not be initialised with previously used details");
|
||||
// Shutdown this API instance, as we will create API instances as required, when required
|
||||
oneDriveApiInstance.shutdown();
|
||||
oneDriveApiInstance.releaseCurlEngine();
|
||||
// Free object and memory
|
||||
object.destroy(oneDriveApiInstance);
|
||||
oneDriveApiInstance = null;
|
||||
//object.destroy(oneDriveApiInstance);
|
||||
//oneDriveApiInstance = null;
|
||||
// Must force exit here, allow logging to be done
|
||||
forceExit();
|
||||
}
|
||||
|
@ -385,11 +385,13 @@ class SyncEngine {
|
|||
addLogEntry("Sync Engine Initialised with new Onedrive API instance", ["verbose"]);
|
||||
|
||||
// Shutdown this API instance, as we will create API instances as required, when required
|
||||
oneDriveApiInstance.shutdown();
|
||||
oneDriveApiInstance.releaseCurlEngine();
|
||||
|
||||
// Free object and memory
|
||||
object.destroy(oneDriveApiInstance);
|
||||
oneDriveApiInstance = null;
|
||||
//object.destroy(oneDriveApiInstance);
|
||||
//oneDriveApiInstance = null;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -481,9 +483,9 @@ class SyncEngine {
|
|||
}
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
getDefaultDriveApiInstance.shutdown();
|
||||
object.destroy(getDefaultDriveApiInstance);
|
||||
getDefaultDriveApiInstance = null;
|
||||
getDefaultDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(getDefaultDriveApiInstance);
|
||||
//getDefaultDriveApiInstance = null;
|
||||
}
|
||||
|
||||
// Get Default Root Details for this Account
|
||||
|
@ -530,9 +532,9 @@ class SyncEngine {
|
|||
}
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
getDefaultRootApiInstance.shutdown();
|
||||
object.destroy(getDefaultRootApiInstance);
|
||||
getDefaultRootApiInstance = null;
|
||||
getDefaultRootApiInstance.releaseCurlEngine();
|
||||
//object.destroy(getDefaultRootApiInstance);
|
||||
//getDefaultRootApiInstance = null;
|
||||
}
|
||||
|
||||
// Reset syncFailures to false based on file activity
|
||||
|
@ -943,9 +945,9 @@ class SyncEngine {
|
|||
addLogEntry("------------------------------------------------------------------", ["debug"]);
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
getDeltaQueryOneDriveApiInstance.shutdown();
|
||||
object.destroy(getDeltaQueryOneDriveApiInstance);
|
||||
getDeltaQueryOneDriveApiInstance = null;
|
||||
getDeltaQueryOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(getDeltaQueryOneDriveApiInstance);
|
||||
//getDeltaQueryOneDriveApiInstance = null;
|
||||
|
||||
// Log that we have finished querying the /delta API
|
||||
if (appConfig.verbosityCount == 0) {
|
||||
|
@ -2247,9 +2249,9 @@ class SyncEngine {
|
|||
downloadFileOneDriveApiInstance.downloadById(downloadDriveId, downloadItemId, newItemPath, jsonFileSize);
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
downloadFileOneDriveApiInstance.shutdown();
|
||||
object.destroy(downloadFileOneDriveApiInstance);
|
||||
downloadFileOneDriveApiInstance = null;
|
||||
downloadFileOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(downloadFileOneDriveApiInstance);
|
||||
//downloadFileOneDriveApiInstance = null;
|
||||
|
||||
} catch (OneDriveException exception) {
|
||||
addLogEntry("downloadFileOneDriveApiInstance.downloadById(downloadDriveId, downloadItemId, newItemPath, jsonFileSize); generated a OneDriveException", ["debug"]);
|
||||
|
@ -2728,9 +2730,9 @@ class SyncEngine {
|
|||
response = uploadLastModifiedTimeApiInstance.updateById(driveId, id, data, eTagValue);
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
uploadLastModifiedTimeApiInstance.shutdown();
|
||||
object.destroy(uploadLastModifiedTimeApiInstance);
|
||||
uploadLastModifiedTimeApiInstance = null;
|
||||
uploadLastModifiedTimeApiInstance.releaseCurlEngine();
|
||||
//object.destroy(uploadLastModifiedTimeApiInstance);
|
||||
//uploadLastModifiedTimeApiInstance = null;
|
||||
|
||||
// Do we actually save the response?
|
||||
// Special case here .. if the DB record item (originItem) is a remote object, thus, if we save the 'response' we will have a DB FOREIGN KEY constraint failed problem
|
||||
|
@ -2764,9 +2766,9 @@ class SyncEngine {
|
|||
}
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
uploadLastModifiedTimeApiInstance.shutdown();
|
||||
object.destroy(uploadLastModifiedTimeApiInstance);
|
||||
uploadLastModifiedTimeApiInstance = null;
|
||||
uploadLastModifiedTimeApiInstance.releaseCurlEngine();
|
||||
//object.destroy(uploadLastModifiedTimeApiInstance);
|
||||
//uploadLastModifiedTimeApiInstance = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3991,9 +3993,9 @@ class SyncEngine {
|
|||
addLogEntry("Modified File Upload Response: " ~ to!string(uploadResponse), ["debug"]);
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
uploadFileOneDriveApiInstance.shutdown();
|
||||
object.destroy(uploadFileOneDriveApiInstance);
|
||||
uploadFileOneDriveApiInstance = null;
|
||||
uploadFileOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(uploadFileOneDriveApiInstance);
|
||||
//uploadFileOneDriveApiInstance = null;
|
||||
|
||||
// Return JSON
|
||||
return uploadResponse;
|
||||
|
@ -4024,9 +4026,9 @@ class SyncEngine {
|
|||
currentDriveQuota = getCurrentDriveQuotaApiInstance.getDriveQuota(driveId);
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
getCurrentDriveQuotaApiInstance.shutdown();
|
||||
object.destroy(getCurrentDriveQuotaApiInstance);
|
||||
getCurrentDriveQuotaApiInstance = null;
|
||||
getCurrentDriveQuotaApiInstance.releaseCurlEngine();
|
||||
//object.destroy(getCurrentDriveQuotaApiInstance);
|
||||
//getCurrentDriveQuotaApiInstance = null;
|
||||
|
||||
} catch (OneDriveException e) {
|
||||
addLogEntry("currentDriveQuota = onedrive.getDriveQuota(driveId) generated a OneDriveException", ["debug"]);
|
||||
|
@ -4710,7 +4712,7 @@ class SyncEngine {
|
|||
// but when we attempted to create it, OneDrive responded that it now already exists
|
||||
addLogEntry("OneDrive reported that " ~ thisNewPathToCreate ~ " already exists .. OneDrive API race condition", ["verbose"]);
|
||||
// Shutdown this API instance, as we will create API instances as required, when required
|
||||
createDirectoryOnlineOneDriveApiInstance.shutdown();
|
||||
createDirectoryOnlineOneDriveApiInstance.releaseCurlEngine();
|
||||
// Free object and memory
|
||||
object.destroy(createDirectoryOnlineOneDriveApiInstance);
|
||||
return;
|
||||
|
@ -4719,7 +4721,7 @@ class SyncEngine {
|
|||
addLogEntry("OneDrive generated an error when creating this path: " ~ thisNewPathToCreate);
|
||||
displayOneDriveErrorMessage(exception.msg, getFunctionName!({}));
|
||||
// Shutdown this API instance, as we will create API instances as required, when required
|
||||
createDirectoryOnlineOneDriveApiInstance.shutdown();
|
||||
createDirectoryOnlineOneDriveApiInstance.releaseCurlEngine();
|
||||
// Free object and memory
|
||||
object.destroy(createDirectoryOnlineOneDriveApiInstance);
|
||||
return;
|
||||
|
@ -4735,7 +4737,7 @@ class SyncEngine {
|
|||
}
|
||||
|
||||
// Shutdown this API instance, as we will create API instances as required, when required
|
||||
createDirectoryOnlineOneDriveApiInstance.shutdown();
|
||||
createDirectoryOnlineOneDriveApiInstance.releaseCurlEngine();
|
||||
// Free object and memory
|
||||
object.destroy(createDirectoryOnlineOneDriveApiInstance);
|
||||
return;
|
||||
|
@ -4781,9 +4783,10 @@ class SyncEngine {
|
|||
// no save to database, no online create
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
createDirectoryOnlineOneDriveApiInstance.shutdown();
|
||||
object.destroy(createDirectoryOnlineOneDriveApiInstance);
|
||||
createDirectoryOnlineOneDriveApiInstance = null;
|
||||
createDirectoryOnlineOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(createDirectoryOnlineOneDriveApiInstance);
|
||||
//createDirectoryOnlineOneDriveApiInstance = null;
|
||||
|
||||
return;
|
||||
} else {
|
||||
// As the 'onlinePathData' is potentially missing the actual correct parent folder id in the 'remoteItem' JSON response, we have to perform a further query to get the correct answer
|
||||
|
@ -4806,9 +4809,10 @@ class SyncEngine {
|
|||
saveItem(onlinePathData);
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
createDirectoryOnlineOneDriveApiInstance.shutdown();
|
||||
object.destroy(createDirectoryOnlineOneDriveApiInstance);
|
||||
createDirectoryOnlineOneDriveApiInstance = null;
|
||||
createDirectoryOnlineOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(createDirectoryOnlineOneDriveApiInstance);
|
||||
//createDirectoryOnlineOneDriveApiInstance = null;
|
||||
|
||||
return;
|
||||
} else {
|
||||
// Normally this would throw an error, however we cant use throw new posixException()
|
||||
|
@ -4821,9 +4825,10 @@ class SyncEngine {
|
|||
posixViolationPaths ~= [thisNewPathToCreate];
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
createDirectoryOnlineOneDriveApiInstance.shutdown();
|
||||
object.destroy(createDirectoryOnlineOneDriveApiInstance);
|
||||
createDirectoryOnlineOneDriveApiInstance = null;
|
||||
createDirectoryOnlineOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(createDirectoryOnlineOneDriveApiInstance);
|
||||
//createDirectoryOnlineOneDriveApiInstance = null;
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
@ -4832,9 +4837,10 @@ class SyncEngine {
|
|||
addLogEntry("ERROR: Increase logging verbosity to assist determining why.");
|
||||
addLogEntry("Skipping: " ~ buildNormalizedPath(absolutePath(thisNewPathToCreate)));
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
createDirectoryOnlineOneDriveApiInstance.shutdown();
|
||||
object.destroy(createDirectoryOnlineOneDriveApiInstance);
|
||||
createDirectoryOnlineOneDriveApiInstance = null;
|
||||
createDirectoryOnlineOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(createDirectoryOnlineOneDriveApiInstance);
|
||||
//createDirectoryOnlineOneDriveApiInstance = null;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -5054,9 +5060,9 @@ class SyncEngine {
|
|||
}
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
checkFileOneDriveApiInstance.shutdown();
|
||||
object.destroy(checkFileOneDriveApiInstance);
|
||||
checkFileOneDriveApiInstance = null;
|
||||
checkFileOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(checkFileOneDriveApiInstance);
|
||||
//checkFileOneDriveApiInstance = null;
|
||||
|
||||
// Portable Operating System Interface (POSIX) testing of JSON response from OneDrive API
|
||||
if (hasName(fileDetailsFromOneDrive)) {
|
||||
|
@ -5120,9 +5126,9 @@ class SyncEngine {
|
|||
}
|
||||
} catch (OneDriveException exception) {
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
checkFileOneDriveApiInstance.shutdown();
|
||||
object.destroy(checkFileOneDriveApiInstance);
|
||||
checkFileOneDriveApiInstance = null;
|
||||
checkFileOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(checkFileOneDriveApiInstance);
|
||||
//checkFileOneDriveApiInstance = null;
|
||||
|
||||
// If we get a 404 .. the file is not online .. this is what we want .. file does not exist online
|
||||
if (exception.httpStatusCode == 404) {
|
||||
|
@ -5139,18 +5145,18 @@ class SyncEngine {
|
|||
}
|
||||
} catch (posixException e) {
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
checkFileOneDriveApiInstance.shutdown();
|
||||
object.destroy(checkFileOneDriveApiInstance);
|
||||
checkFileOneDriveApiInstance = null;
|
||||
checkFileOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(checkFileOneDriveApiInstance);
|
||||
//checkFileOneDriveApiInstance = null;
|
||||
|
||||
// Display POSIX error message
|
||||
displayPosixErrorMessage(e.msg);
|
||||
uploadFailed = true;
|
||||
} catch (jsonResponseException e) {
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
checkFileOneDriveApiInstance.shutdown();
|
||||
object.destroy(checkFileOneDriveApiInstance);
|
||||
checkFileOneDriveApiInstance = null;
|
||||
checkFileOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(checkFileOneDriveApiInstance);
|
||||
//checkFileOneDriveApiInstance = null;
|
||||
|
||||
// Display JSON error message
|
||||
addLogEntry(e.msg, ["debug"]);
|
||||
|
@ -5238,9 +5244,9 @@ class SyncEngine {
|
|||
addLogEntry("Uploading new file: " ~ fileToUpload ~ " ... done.");
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
uploadFileOneDriveApiInstance.shutdown();
|
||||
object.destroy(uploadFileOneDriveApiInstance);
|
||||
uploadFileOneDriveApiInstance = null;
|
||||
uploadFileOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(uploadFileOneDriveApiInstance);
|
||||
//uploadFileOneDriveApiInstance = null;
|
||||
|
||||
} catch (OneDriveException exception) {
|
||||
// An error was responded with - what was it
|
||||
|
@ -5253,9 +5259,9 @@ class SyncEngine {
|
|||
displayOneDriveErrorMessage(exception.msg, thisFunctionName);
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
uploadFileOneDriveApiInstance.shutdown();
|
||||
object.destroy(uploadFileOneDriveApiInstance);
|
||||
uploadFileOneDriveApiInstance = null;
|
||||
uploadFileOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(uploadFileOneDriveApiInstance);
|
||||
//uploadFileOneDriveApiInstance = null;
|
||||
|
||||
} catch (FileException e) {
|
||||
// display the error message
|
||||
|
@ -5263,9 +5269,9 @@ class SyncEngine {
|
|||
displayFileSystemErrorMessage(e.msg, getFunctionName!({}));
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
uploadFileOneDriveApiInstance.shutdown();
|
||||
object.destroy(uploadFileOneDriveApiInstance);
|
||||
uploadFileOneDriveApiInstance = null;
|
||||
uploadFileOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(uploadFileOneDriveApiInstance);
|
||||
//uploadFileOneDriveApiInstance = null;
|
||||
}
|
||||
} else {
|
||||
// Initialise API for session upload
|
||||
|
@ -5355,9 +5361,9 @@ class SyncEngine {
|
|||
}
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
uploadFileOneDriveApiInstance.shutdown();
|
||||
object.destroy(uploadFileOneDriveApiInstance);
|
||||
uploadFileOneDriveApiInstance = null;
|
||||
uploadFileOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(uploadFileOneDriveApiInstance);
|
||||
//uploadFileOneDriveApiInstance = null;
|
||||
}
|
||||
} else {
|
||||
// We are in a --dry-run scenario
|
||||
|
@ -5682,9 +5688,9 @@ class SyncEngine {
|
|||
uploadDeletedItemOneDriveApiInstance.deleteById(itemToDelete.driveId, itemToDelete.id);
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
uploadDeletedItemOneDriveApiInstance.shutdown();
|
||||
object.destroy(uploadDeletedItemOneDriveApiInstance);
|
||||
uploadDeletedItemOneDriveApiInstance = null;
|
||||
uploadDeletedItemOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(uploadDeletedItemOneDriveApiInstance);
|
||||
//uploadDeletedItemOneDriveApiInstance = null;
|
||||
|
||||
} catch (OneDriveException e) {
|
||||
if (e.httpStatusCode == 404) {
|
||||
|
@ -5693,9 +5699,9 @@ class SyncEngine {
|
|||
}
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
uploadDeletedItemOneDriveApiInstance.shutdown();
|
||||
object.destroy(uploadDeletedItemOneDriveApiInstance);
|
||||
uploadDeletedItemOneDriveApiInstance = null;
|
||||
uploadDeletedItemOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(uploadDeletedItemOneDriveApiInstance);
|
||||
//uploadDeletedItemOneDriveApiInstance = null;
|
||||
}
|
||||
|
||||
// Delete the reference in the local database
|
||||
|
@ -5756,9 +5762,9 @@ class SyncEngine {
|
|||
performReverseDeletionOneDriveApiInstance.deleteById(itemToDelete.driveId, itemToDelete.id, itemToDelete.eTag);
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
performReverseDeletionOneDriveApiInstance.shutdown();
|
||||
object.destroy(performReverseDeletionOneDriveApiInstance);
|
||||
performReverseDeletionOneDriveApiInstance = null;
|
||||
performReverseDeletionOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(performReverseDeletionOneDriveApiInstance);
|
||||
//performReverseDeletionOneDriveApiInstance = null;
|
||||
}
|
||||
|
||||
// Create a fake OneDrive response suitable for use with saveItem
|
||||
|
@ -6090,9 +6096,9 @@ class SyncEngine {
|
|||
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
generateDeltaResponseOneDriveApiInstance.shutdown();
|
||||
object.destroy(generateDeltaResponseOneDriveApiInstance);
|
||||
generateDeltaResponseOneDriveApiInstance = null;
|
||||
generateDeltaResponseOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(generateDeltaResponseOneDriveApiInstance);
|
||||
//generateDeltaResponseOneDriveApiInstance = null;
|
||||
|
||||
// Must force exit here, allow logging to be done
|
||||
forceExit();
|
||||
|
@ -6172,7 +6178,7 @@ class SyncEngine {
|
|||
// driveData is an invalid JSON object
|
||||
writeln("CODING TO DO: The query of OneDrive API to getPathDetailsById generated an invalid JSON response - thus we cant build our own /delta simulated response ... how to handle?");
|
||||
// Must exit here
|
||||
generateDeltaResponseOneDriveApiInstance.shutdown();
|
||||
generateDeltaResponseOneDriveApiInstance.releaseCurlEngine();
|
||||
// Free object and memory
|
||||
object.destroy(generateDeltaResponseOneDriveApiInstance);
|
||||
// Must force exit here, allow logging to be done
|
||||
|
@ -6260,9 +6266,9 @@ class SyncEngine {
|
|||
];
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
generateDeltaResponseOneDriveApiInstance.shutdown();
|
||||
object.destroy(generateDeltaResponseOneDriveApiInstance);
|
||||
generateDeltaResponseOneDriveApiInstance = null;
|
||||
generateDeltaResponseOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(generateDeltaResponseOneDriveApiInstance);
|
||||
//generateDeltaResponseOneDriveApiInstance = null;
|
||||
|
||||
// Return the generated JSON response
|
||||
return selfGeneratedDeltaResponse;
|
||||
|
@ -6354,9 +6360,9 @@ class SyncEngine {
|
|||
}
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
queryChildrenOneDriveApiInstance.shutdown();
|
||||
object.destroy(queryChildrenOneDriveApiInstance);
|
||||
queryChildrenOneDriveApiInstance = null;
|
||||
queryChildrenOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(queryChildrenOneDriveApiInstance);
|
||||
//queryChildrenOneDriveApiInstance = null;
|
||||
|
||||
// return response
|
||||
return thisLevelChildrenData;
|
||||
|
@ -6620,9 +6626,9 @@ class SyncEngine {
|
|||
}
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
queryOneDriveForSpecificPath.shutdown();
|
||||
object.destroy(queryOneDriveForSpecificPath);
|
||||
queryOneDriveForSpecificPath = null;
|
||||
queryOneDriveForSpecificPath.releaseCurlEngine();
|
||||
//object.destroy(queryOneDriveForSpecificPath);
|
||||
//queryOneDriveForSpecificPath = null;
|
||||
|
||||
// Output our search results
|
||||
addLogEntry("queryOneDriveForSpecificPathAndCreateIfMissing.getPathDetailsAPIResponse = " ~ to!string(getPathDetailsAPIResponse), ["debug"]);
|
||||
|
@ -6827,9 +6833,9 @@ class SyncEngine {
|
|||
}
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
movePathOnlineApiInstance.shutdown();
|
||||
object.destroy(movePathOnlineApiInstance);
|
||||
movePathOnlineApiInstance = null;
|
||||
movePathOnlineApiInstance.releaseCurlEngine();
|
||||
//object.destroy(movePathOnlineApiInstance);
|
||||
//movePathOnlineApiInstance = null;
|
||||
|
||||
// save the move response from OneDrive in the database
|
||||
// Is the response a valid JSON object - validation checking done in saveItem
|
||||
|
@ -6941,9 +6947,10 @@ class SyncEngine {
|
|||
addLogEntry("ERROR: Authentication scope needs to be updated. Use --reauth and re-authenticate client.");
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
querySharePointLibraryNameApiInstance.shutdown();
|
||||
object.destroy(querySharePointLibraryNameApiInstance);
|
||||
querySharePointLibraryNameApiInstance = null;
|
||||
querySharePointLibraryNameApiInstance.releaseCurlEngine();
|
||||
//object.destroy(querySharePointLibraryNameApiInstance);
|
||||
//querySharePointLibraryNameApiInstance = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -6960,9 +6967,10 @@ class SyncEngine {
|
|||
addLogEntry("ERROR: To resolve, please discuss this issue with whomever supports your OneDrive and SharePoint environment.");
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
querySharePointLibraryNameApiInstance.shutdown();
|
||||
object.destroy(querySharePointLibraryNameApiInstance);
|
||||
querySharePointLibraryNameApiInstance = null;
|
||||
querySharePointLibraryNameApiInstance.releaseCurlEngine();
|
||||
//object.destroy(querySharePointLibraryNameApiInstance);
|
||||
//querySharePointLibraryNameApiInstance = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -6972,9 +6980,10 @@ class SyncEngine {
|
|||
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
querySharePointLibraryNameApiInstance.shutdown();
|
||||
object.destroy(querySharePointLibraryNameApiInstance);
|
||||
querySharePointLibraryNameApiInstance = null;
|
||||
querySharePointLibraryNameApiInstance.releaseCurlEngine();
|
||||
//object.destroy(querySharePointLibraryNameApiInstance);
|
||||
//querySharePointLibraryNameApiInstance = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -7000,10 +7009,12 @@ class SyncEngine {
|
|||
addLogEntry("ERROR: Query of OneDrive for Office Site ID failed");
|
||||
// display what the error is
|
||||
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
querySharePointLibraryNameApiInstance.shutdown();
|
||||
object.destroy(querySharePointLibraryNameApiInstance);
|
||||
querySharePointLibraryNameApiInstance = null;
|
||||
querySharePointLibraryNameApiInstance.releaseCurlEngine();
|
||||
//object.destroy(querySharePointLibraryNameApiInstance);
|
||||
//querySharePointLibraryNameApiInstance = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -7026,10 +7037,12 @@ class SyncEngine {
|
|||
// not a valid JSON object
|
||||
addLogEntry("ERROR: There was an error performing this operation on Microsoft OneDrive");
|
||||
addLogEntry("ERROR: Increase logging verbosity to assist determining why.");
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
querySharePointLibraryNameApiInstance.shutdown();
|
||||
object.destroy(querySharePointLibraryNameApiInstance);
|
||||
querySharePointLibraryNameApiInstance = null;
|
||||
querySharePointLibraryNameApiInstance.releaseCurlEngine();
|
||||
//object.destroy(querySharePointLibraryNameApiInstance);
|
||||
//querySharePointLibraryNameApiInstance = null;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -7081,9 +7094,10 @@ class SyncEngine {
|
|||
addLogEntry("ERROR: Increase logging verbosity to assist determining why.");
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
querySharePointLibraryNameApiInstance.shutdown();
|
||||
object.destroy(querySharePointLibraryNameApiInstance);
|
||||
querySharePointLibraryNameApiInstance = null;
|
||||
querySharePointLibraryNameApiInstance.releaseCurlEngine();
|
||||
//object.destroy(querySharePointLibraryNameApiInstance);
|
||||
//querySharePointLibraryNameApiInstance = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -7114,9 +7128,9 @@ class SyncEngine {
|
|||
}
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
querySharePointLibraryNameApiInstance.shutdown();
|
||||
object.destroy(querySharePointLibraryNameApiInstance);
|
||||
querySharePointLibraryNameApiInstance = null;
|
||||
querySharePointLibraryNameApiInstance.releaseCurlEngine();
|
||||
//object.destroy(querySharePointLibraryNameApiInstance);
|
||||
//querySharePointLibraryNameApiInstance = null;
|
||||
}
|
||||
|
||||
// Query the sync status of the client and the local system
|
||||
|
@ -7226,9 +7240,9 @@ class SyncEngine {
|
|||
}
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
getDeltaQueryOneDriveApiInstance.shutdown();
|
||||
object.destroy(getDeltaQueryOneDriveApiInstance);
|
||||
getDeltaQueryOneDriveApiInstance = null;
|
||||
getDeltaQueryOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(getDeltaQueryOneDriveApiInstance);
|
||||
//getDeltaQueryOneDriveApiInstance = null;
|
||||
|
||||
// Needed after printing out '....' when fetching changes from OneDrive API
|
||||
if (appConfig.verbosityCount == 0)
|
||||
|
@ -7331,9 +7345,10 @@ class SyncEngine {
|
|||
displayOneDriveErrorMessage(exception.msg, getFunctionName!({}));
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
queryOneDriveForFileDetailsApiInstance.shutdown();
|
||||
object.destroy(queryOneDriveForFileDetailsApiInstance);
|
||||
queryOneDriveForFileDetailsApiInstance = null;
|
||||
queryOneDriveForFileDetailsApiInstance.releaseCurlEngine();
|
||||
//object.destroy(queryOneDriveForFileDetailsApiInstance);
|
||||
//queryOneDriveForFileDetailsApiInstance = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -7414,9 +7429,9 @@ class SyncEngine {
|
|||
}
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
queryOneDriveForFileDetailsApiInstance.shutdown();
|
||||
object.destroy(queryOneDriveForFileDetailsApiInstance);
|
||||
queryOneDriveForFileDetailsApiInstance = null;
|
||||
queryOneDriveForFileDetailsApiInstance.releaseCurlEngine();
|
||||
//object.destroy(queryOneDriveForFileDetailsApiInstance);
|
||||
//queryOneDriveForFileDetailsApiInstance = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7452,15 +7467,16 @@ class SyncEngine {
|
|||
currentDriveQuota = getCurrentDriveQuotaApiInstance.getDriveQuota(driveId);
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
getCurrentDriveQuotaApiInstance.shutdown();
|
||||
object.destroy(getCurrentDriveQuotaApiInstance);
|
||||
getCurrentDriveQuotaApiInstance = null;
|
||||
getCurrentDriveQuotaApiInstance.releaseCurlEngine();
|
||||
//object.destroy(getCurrentDriveQuotaApiInstance);
|
||||
//getCurrentDriveQuotaApiInstance = null;
|
||||
|
||||
} catch (OneDriveException e) {
|
||||
addLogEntry("currentDriveQuota = onedrive.getDriveQuota(driveId) generated a OneDriveException", ["debug"]);
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
getCurrentDriveQuotaApiInstance.shutdown();
|
||||
object.destroy(getCurrentDriveQuotaApiInstance);
|
||||
getCurrentDriveQuotaApiInstance = null;
|
||||
getCurrentDriveQuotaApiInstance.releaseCurlEngine();
|
||||
//object.destroy(getCurrentDriveQuotaApiInstance);
|
||||
//getCurrentDriveQuotaApiInstance = null;
|
||||
}
|
||||
|
||||
// validate that currentDriveQuota is a JSON value
|
||||
|
@ -7649,18 +7665,19 @@ class SyncEngine {
|
|||
response = validateUploadSessionFileDataApiInstance.requestUploadStatus(sessionFileData["uploadUrl"].str);
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
validateUploadSessionFileDataApiInstance.shutdown();
|
||||
object.destroy(validateUploadSessionFileDataApiInstance);
|
||||
validateUploadSessionFileDataApiInstance = null;
|
||||
validateUploadSessionFileDataApiInstance.releaseCurlEngine();
|
||||
//object.destroy(validateUploadSessionFileDataApiInstance);
|
||||
//validateUploadSessionFileDataApiInstance = null;
|
||||
|
||||
} catch (OneDriveException e) {
|
||||
// handle any onedrive error response as invalid
|
||||
addLogEntry("SESSION-RESUME: Invalid response when using uploadUrl in: " ~ sessionFilePath, ["debug"]);
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
validateUploadSessionFileDataApiInstance.shutdown();
|
||||
object.destroy(validateUploadSessionFileDataApiInstance);
|
||||
validateUploadSessionFileDataApiInstance = null;
|
||||
validateUploadSessionFileDataApiInstance.releaseCurlEngine();
|
||||
//object.destroy(validateUploadSessionFileDataApiInstance);
|
||||
//validateUploadSessionFileDataApiInstance = null;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -7723,9 +7740,9 @@ class SyncEngine {
|
|||
}
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
uploadFileOneDriveApiInstance.shutdown();
|
||||
object.destroy(uploadFileOneDriveApiInstance);
|
||||
uploadFileOneDriveApiInstance = null;
|
||||
uploadFileOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(uploadFileOneDriveApiInstance);
|
||||
//uploadFileOneDriveApiInstance = null;
|
||||
|
||||
// Was the response from the OneDrive API a valid JSON item?
|
||||
if (uploadResponse.type() == JSONType.object) {
|
||||
|
@ -7852,9 +7869,9 @@ class SyncEngine {
|
|||
// Operations in this thread are done / complete
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
checkFileOneDriveApiInstance.shutdown();
|
||||
object.destroy(checkFileOneDriveApiInstance);
|
||||
checkFileOneDriveApiInstance = null;
|
||||
checkFileOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(checkFileOneDriveApiInstance);
|
||||
//checkFileOneDriveApiInstance = null;
|
||||
|
||||
// Return child
|
||||
return child;
|
||||
|
@ -7871,9 +7888,9 @@ class SyncEngine {
|
|||
}
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
checkFileOneDriveApiInstance.shutdown();
|
||||
object.destroy(checkFileOneDriveApiInstance);
|
||||
checkFileOneDriveApiInstance = null;
|
||||
checkFileOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(checkFileOneDriveApiInstance);
|
||||
//checkFileOneDriveApiInstance = null;
|
||||
|
||||
// return an empty JSON item
|
||||
return onedriveJSONItem;
|
||||
|
@ -8001,18 +8018,19 @@ class SyncEngine {
|
|||
sharedWithMeItems = sharedWithMeOneDriveApiInstance.getSharedWithMe();
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
sharedWithMeOneDriveApiInstance.shutdown();
|
||||
object.destroy(sharedWithMeOneDriveApiInstance);
|
||||
sharedWithMeOneDriveApiInstance = null;
|
||||
sharedWithMeOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(sharedWithMeOneDriveApiInstance);
|
||||
//sharedWithMeOneDriveApiInstance = null;
|
||||
|
||||
} catch (OneDriveException e) {
|
||||
// Display error message
|
||||
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
sharedWithMeOneDriveApiInstance.shutdown();
|
||||
object.destroy(sharedWithMeOneDriveApiInstance);
|
||||
sharedWithMeOneDriveApiInstance = null;
|
||||
sharedWithMeOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(sharedWithMeOneDriveApiInstance);
|
||||
//sharedWithMeOneDriveApiInstance = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -8104,9 +8122,10 @@ class SyncEngine {
|
|||
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
sharedWithMeOneDriveApiInstance.shutdown();
|
||||
object.destroy(sharedWithMeOneDriveApiInstance);
|
||||
sharedWithMeOneDriveApiInstance = null;
|
||||
sharedWithMeOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(sharedWithMeOneDriveApiInstance);
|
||||
//sharedWithMeOneDriveApiInstance = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -8309,8 +8328,8 @@ class SyncEngine {
|
|||
}
|
||||
|
||||
// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
|
||||
sharedWithMeOneDriveApiInstance.shutdown();
|
||||
object.destroy(sharedWithMeOneDriveApiInstance);
|
||||
sharedWithMeOneDriveApiInstance = null;
|
||||
sharedWithMeOneDriveApiInstance.releaseCurlEngine();
|
||||
//object.destroy(sharedWithMeOneDriveApiInstance);
|
||||
//sharedWithMeOneDriveApiInstance = null;
|
||||
}
|
||||
}
|
92
src/util.d
92
src/util.d
|
@ -202,44 +202,6 @@ Regex!char wild2regex(const(char)[] pattern) {
|
|||
return regex(str, "i");
|
||||
}
|
||||
|
||||
// Test Internet access to Microsoft OneDrive
|
||||
bool testInternetReachabilityCurlPool(ApplicationConfig appConfig) {
|
||||
CurlEngine curlEngine;
|
||||
bool result = false;
|
||||
try {
|
||||
// Use preconfigured object with all the correct http values assigned
|
||||
curlEngine = CurlEngine.getCurlInstance();
|
||||
curlEngine.initialise(appConfig.getValueLong("dns_timeout"), appConfig.getValueLong("connect_timeout"), appConfig.getValueLong("data_timeout"), appConfig.getValueLong("operation_timeout"), appConfig.defaultMaxRedirects, appConfig.getValueBool("debug_https"), appConfig.getValueString("user_agent"), appConfig.getValueBool("force_http_11"), appConfig.getValueLong("rate_limit"), appConfig.getValueLong("ip_protocol_version"));
|
||||
|
||||
// Configure the remaining items required
|
||||
// URL to use
|
||||
// HTTP connection test method
|
||||
|
||||
curlEngine.connect(HTTP.Method.head, "https://login.microsoftonline.com");
|
||||
addLogEntry("Attempting to contact Microsoft OneDrive Login Service", ["debug"]);
|
||||
curlEngine.http.perform();
|
||||
addLogEntry("Shutting down HTTP engine as successfully reached OneDrive Login Service", ["debug"]);
|
||||
|
||||
// Release
|
||||
curlEngine.release(); // performs curl cleanup()
|
||||
curlEngine = null; // Clean up this memory variable
|
||||
|
||||
// Set that we are online
|
||||
result = true;
|
||||
} catch (SocketException e) {
|
||||
addLogEntry("HTTP Socket Issue", ["debug"]);
|
||||
addLogEntry("Cannot connect to Microsoft OneDrive Login Service - Socket Issue");
|
||||
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
||||
} catch (CurlException e) {
|
||||
addLogEntry("No Network Connection", ["debug"]);
|
||||
addLogEntry("Cannot connect to Microsoft OneDrive Login Service - Network Connection Issue");
|
||||
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
||||
}
|
||||
|
||||
// Return test result
|
||||
return result;
|
||||
}
|
||||
|
||||
// Test Internet access to Microsoft OneDrive using a simple HTTP HEAD request
|
||||
bool testInternetReachability(ApplicationConfig appConfig) {
|
||||
auto http = HTTP();
|
||||
|
@ -259,34 +221,38 @@ bool testInternetReachability(ApplicationConfig appConfig) {
|
|||
|
||||
// Execute the request and handle exceptions
|
||||
try {
|
||||
addLogEntry("Attempting to contact Microsoft OneDrive Login Service");
|
||||
http.perform();
|
||||
addLogEntry("Attempting to contact Microsoft OneDrive Login Service");
|
||||
http.perform();
|
||||
|
||||
// Check response for HTTP status code
|
||||
if (http.statusLine.code >= 200 && http.statusLine.code < 400) {
|
||||
addLogEntry("Successfully reached Microsoft OneDrive Login Service");
|
||||
} else {
|
||||
addLogEntry("Failed to reach Microsoft OneDrive Login Service. HTTP status code: " ~ to!string(http.statusLine.code));
|
||||
throw new Exception("HTTP Request Failed with Status Code: " ~ to!string(http.statusLine.code));
|
||||
}
|
||||
// Check response for HTTP status code
|
||||
if (http.statusLine.code >= 200 && http.statusLine.code < 400) {
|
||||
addLogEntry("Successfully reached Microsoft OneDrive Login Service");
|
||||
} else {
|
||||
addLogEntry("Failed to reach Microsoft OneDrive Login Service. HTTP status code: " ~ to!string(http.statusLine.code));
|
||||
throw new Exception("HTTP Request Failed with Status Code: " ~ to!string(http.statusLine.code));
|
||||
}
|
||||
|
||||
http.shutdown();
|
||||
return true;
|
||||
http.shutdown();
|
||||
object.destroy(http);
|
||||
return true;
|
||||
} catch (SocketException e) {
|
||||
addLogEntry("Cannot connect to Microsoft OneDrive Service - Socket Issue: " ~ e.msg);
|
||||
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
||||
http.shutdown();
|
||||
return false;
|
||||
addLogEntry("Cannot connect to Microsoft OneDrive Service - Socket Issue: " ~ e.msg);
|
||||
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
||||
http.shutdown();
|
||||
object.destroy(http);
|
||||
return false;
|
||||
} catch (CurlException e) {
|
||||
addLogEntry("Cannot connect to Microsoft OneDrive Service - Network Connection Issue: " ~ e.msg);
|
||||
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
||||
http.shutdown();
|
||||
return false;
|
||||
addLogEntry("Cannot connect to Microsoft OneDrive Service - Network Connection Issue: " ~ e.msg);
|
||||
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
||||
http.shutdown();
|
||||
object.destroy(http);
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
addLogEntry("Unexpected error occurred: " ~ e.toString());
|
||||
displayOneDriveErrorMessage(e.toString(), getFunctionName!({}));
|
||||
http.shutdown();
|
||||
return false;
|
||||
addLogEntry("Unexpected error occurred: " ~ e.toString());
|
||||
displayOneDriveErrorMessage(e.toString(), getFunctionName!({}));
|
||||
http.shutdown();
|
||||
object.destroy(http);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -757,7 +723,7 @@ JSONValue fetchOnlineURLContent(string url) {
|
|||
// Ensure resources are cleaned up
|
||||
http.shutdown();
|
||||
object.destroy(http);
|
||||
|
||||
|
||||
// Return onlineResponse
|
||||
return onlineContent;
|
||||
}
|
||||
|
@ -1152,8 +1118,8 @@ void displayMemoryUsagePostGC() {
|
|||
addLogEntry();
|
||||
}
|
||||
|
||||
// Write internal memory stats
|
||||
void writeMemoryStats() {
|
||||
// write memory stats
|
||||
addLogEntry("current memory usedSize = " ~ to!string((GC.stats.usedSize/1024))); // number of used bytes on the GC heap (might only get updated after a collection)
|
||||
addLogEntry("current memory freeSize = " ~ to!string((GC.stats.freeSize/1024))); // number of free bytes on the GC heap (might only get updated after a collection)
|
||||
addLogEntry("current memory allocatedInCurrentThread = " ~ to!string((GC.stats.allocatedInCurrentThread/1024))); // number of bytes allocated for current thread since program start
|
||||
|
|
|
@ -78,8 +78,8 @@ class OneDriveWebhook {
|
|||
} catch (OneDriveException e) {
|
||||
logSubscriptionError(e);
|
||||
}
|
||||
oneDriveApiInstance.shutdown();
|
||||
object.destroy(oneDriveApiInstance);
|
||||
// Release API instance back to the pool
|
||||
oneDriveApiInstance.releaseCurlEngine();
|
||||
}
|
||||
|
||||
private static void handle(shared OneDriveWebhook _this, Cgi cgi) {
|
||||
|
|
Loading…
Reference in a new issue