import/restore: automatically detect prefix from the full path
This commit is contained in:
+23
-2
@@ -739,6 +739,25 @@ function getColor(numOfSteps, step) {
|
||||
return `hsl(${deg*step} 70% 50%)`;
|
||||
}
|
||||
|
||||
// split path into a prefix (anything before timestamp or 'snapshot') and the remaining remotePath
|
||||
function parseFullBackupPath(fullPath) {
|
||||
const parts = fullPath.split('/');
|
||||
const timestampRegex = /^\d{4}-\d{2}-\d{2}-\d{6}-\d{3}$/; // timestamp (tag)
|
||||
|
||||
const idx = parts.findIndex(p => timestampRegex.test(p) || p === 'snapshot');
|
||||
|
||||
let remotePath, prefix;
|
||||
if (idx === -1) {
|
||||
remotePath = parts.pop() || parts.pop(); // if fs+rsync there may be a trailing slash, so this removes it. this is basename()
|
||||
prefix = parts.join('/'); // this is dirname()
|
||||
} else {
|
||||
prefix = parts.slice(0, idx).join('/');
|
||||
remotePath = parts.slice(idx).join('/');
|
||||
}
|
||||
|
||||
return { prefix, remotePath };
|
||||
}
|
||||
|
||||
// named exports
|
||||
export {
|
||||
prettyRelayProviderName,
|
||||
@@ -757,7 +776,8 @@ export {
|
||||
getColor,
|
||||
prettySchedule,
|
||||
parseSchedule,
|
||||
prettySiteLocation
|
||||
prettySiteLocation,
|
||||
parseFullBackupPath
|
||||
};
|
||||
|
||||
// default export
|
||||
@@ -778,5 +798,6 @@ export default {
|
||||
getColor,
|
||||
prettySchedule,
|
||||
parseSchedule,
|
||||
prettySiteLocation
|
||||
prettySiteLocation,
|
||||
parseFullBackupPath
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user