Support S3 delete

This commit is contained in:
2020-12-12 14:45:26 -06:00
parent 7e0f06ba56
commit 54bc306fb0
5 changed files with 99 additions and 89 deletions

View File

@@ -20,29 +20,29 @@ const clearManualMountDetection = provider => {
const monitorMount = (sender, provider, providerList, version, pid, location) => {
manualMountDetection[provider] = setInterval(() => {
helpers
.detectRepertoryMounts(version, providerList)
.then(result => {
if (result[provider].PID !== pid) {
if (result[provider].PID === -1) {
clearManualMountDetection(provider);
sender.send(Constants.IPC_Unmount_Drive_Reply, {
data: {
Expected: expectedUnmount[provider],
Location: location,
Provider: provider,
Error: Error(provider + ' Unmounted').toString(),
Success: false,
}
});
} else {
pid = result[provider].PID;
}
.detectRepertoryMounts(version, providerList)
.then(result => {
if (result[provider].PID !== pid) {
if (result[provider].PID === -1) {
clearManualMountDetection(provider);
sender.send(Constants.IPC_Unmount_Drive_Reply, {
data: {
Expected: expectedUnmount[provider],
Location: location,
Provider: provider,
Error: Error(provider + ' Unmounted').toString(),
Success: false,
}
});
} else {
pid = result[provider].PID;
}
})
.catch(e => {
console.log(e);
});
},6000);
}
})
.catch(e => {
console.log(e);
});
}, 6000);
};
const unmountAllDrives = () => {
@@ -149,52 +149,52 @@ const addListeners = (ipcMain, {setTrayImage, standardIPCReply}) => {
};
helpers
.detectRepertoryMounts(data.Version, providerList)
.then((results) => {
let storageData = {};
let locations = {};
for (const provider of providerList) {
storageData[provider] = results[provider] ? results[provider] : {
Active: false,
Location: '',
PID: -1,
};
locations[provider] = storageData[provider].Location;
.detectRepertoryMounts(data.Version, providerList)
.then((results) => {
let storageData = {};
let locations = {};
for (const provider of providerList) {
storageData[provider] = results[provider] ? results[provider] : {
Active: false,
Location: '',
PID: -1,
};
locations[provider] = storageData[provider].Location;
if (storageData[provider].PID !== -1) {
expectedUnmount[provider] = false;
if (firstMountCheck) {
monitorMount(event.sender, provider, providerList, data.Version, storageData[provider].PID, storageData[provider].Location);
}
if (storageData[provider].PID !== -1) {
expectedUnmount[provider] = false;
if (firstMountCheck) {
monitorMount(event.sender, provider, providerList, data.Version, storageData[provider].PID, storageData[provider].Location);
}
}
}
if (os.platform() === 'win32') {
grabDriveLetters(locations);
}
if (os.platform() === 'win32') {
grabDriveLetters(locations);
}
setImage(locations);
if (firstMountCheck) {
firstMountCheck = false;
}
standardIPCReply(event, Constants.IPC_Detect_Mount_Reply, {
Active: storageData[provider].Active,
DriveLetters: driveLetters[provider],
Location: locations[provider],
PID: storageData[provider].PID,
Provider: provider,
});
})
.catch(error => {
if (os.platform() === 'win32') {
grabDriveLetters({});
}
setImage({});
standardIPCReply(event, Constants.IPC_Detect_Mount_Reply, {
DriveLetters: driveLetters[provider],
Provider: provider,
}, error);
setImage(locations);
if (firstMountCheck) {
firstMountCheck = false;
}
standardIPCReply(event, Constants.IPC_Detect_Mount_Reply, {
Active: storageData[provider].Active,
DriveLetters: driveLetters[provider],
Location: locations[provider],
PID: storageData[provider].PID,
Provider: provider,
});
})
.catch(error => {
if (os.platform() === 'win32') {
grabDriveLetters({});
}
setImage({});
standardIPCReply(event, Constants.IPC_Detect_Mount_Reply, {
DriveLetters: driveLetters[provider],
Provider: provider,
}, error);
});
});
ipcMain.on(Constants.IPC_Mount_Drive, (event, data) => {
@@ -241,15 +241,17 @@ const addListeners = (ipcMain, {setTrayImage, standardIPCReply}) => {
}
});
ipcMain.on(Constants.IPC_Remove_Remote_Mount, (event, data) => {
data = data.replace(':', '_');
const dataDirectory = path.resolve(path.join(helpers.getDataDirectory(), '..', 'remote', data));
ipcMain.on(Constants.IPC_Remove_Mount, (event, data) => {
if (data.Remote) {
data.Name = data.Name.replace(':', '_');
}
const dataDirectory = path.resolve(path.join(helpers.getDataDirectory(), '..', data.Remote ? 'remote' : 's3', data.Name));
try {
helpers.removeDirectoryRecursively(dataDirectory);
standardIPCReply(event, Constants.IPC_Remove_Remote_Mount_Reply, {DataDirectory: dataDirectory});
standardIPCReply(event, Constants.IPC_Remove_Mount_Reply, {DataDirectory: dataDirectory});
} catch (e) {
standardIPCReply(event, Constants.IPC_Remove_Remote_Mount_Reply, {DataDirectory: dataDirectory}, e);
standardIPCReply(event, Constants.IPC_Remove_Mount_Reply, {DataDirectory: dataDirectory}, e);
}
});
@@ -264,12 +266,12 @@ const addListeners = (ipcMain, {setTrayImage, standardIPCReply}) => {
expectedUnmount[data.Provider] = true;
helpers
.stopMountProcess(data.Version, data.Provider, data.Remote, data.S3)
.then(result => {
console.log(result);
})
.catch(e => {
console.log(e);
});
.then(result => {
console.log(result);
})
.catch(e => {
console.log(e);
});
});
};