import/restore: automatically detect prefix from the full path

This commit is contained in:
Girish Ramakrishnan
2025-11-26 11:38:06 +01:00
parent 8ec4659949
commit 104318ab8c
3 changed files with 50 additions and 28 deletions
+23 -2
View File
@@ -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
};