Skip to content

Commit ce14d1a

Browse files
authored
Fix: Handling package paths in different drives than user home dir or zap file location (#1547)
1 parent dc0747a commit ce14d1a

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src-electron/importexport/export.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ async function exportSessionPackages(db, sessionId, zapProjectFileLocation) {
136136
pathRelativity = dbEnum.pathRelativity.relativeToZap
137137
}
138138
}
139+
if (path.isAbsolute(relativePath) && /^[A-Z]:\\/i.test(relativePath)) {
140+
// Handling Windows path when package is on different drive than zapProjectFile or user home
141+
pathRelativity = dbEnum.pathRelativity.absolute
142+
}
139143
let ret = {
140144
pathRelativity: pathRelativity,
141145
path: relativePath,

src-electron/importexport/import-json.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const queryCommand = require('../db/query-command.js')
3737
const conformChecker = require('../validation/conformance-checker.js')
3838
const zclLoader = require('../zcl/zcl-loader.js')
3939
const generationEngine = require('../generator/generation-engine')
40+
const path = require('path')
4041

4142
/**
4243
* Resolves with a promise that imports session key values.
@@ -730,6 +731,46 @@ async function importEvents(
730731
}
731732
}
732733

734+
/**
735+
* Checks if any package path is on a different drive than the zap file path (Windows only)
736+
* and sets appropriate warnings
737+
* @param {*} db
738+
* @param {*} packages
739+
* @param {*} zapFilePath
740+
* @param {*} sessionId
741+
*/
742+
async function validatePackagePathDrive(db, packages, zapFilePath, sessionId) {
743+
// If zap file path is not a windows path, skip check
744+
if (!/^[A-Z]:/i.test(zapFilePath)) {
745+
return
746+
}
747+
748+
let zapDrive = zapFilePath.split(':')[0]
749+
for (const pkg of packages) {
750+
let packagePath = pkg.path
751+
if (
752+
packagePath &&
753+
packagePath.split(':')[0] !== zapDrive &&
754+
path.isAbsolute(packagePath)
755+
) {
756+
let message =
757+
"Package path '" +
758+
packagePath +
759+
"' is on a different drive than the .zap file path. " +
760+
'It is recommended that all packages reside on the same drive as the .zap file.'
761+
querySessionNotice.setNotification(
762+
db,
763+
'WARNING',
764+
message,
765+
sessionId,
766+
1,
767+
0
768+
)
769+
env.logWarning(message)
770+
}
771+
}
772+
}
773+
733774
/**
734775
* Retrieves the mandatory attributes of a cluster
735776
* @param {*} db
@@ -1693,6 +1734,14 @@ async function jsonDataLoader(
16931734
pkg.type == dbEnum.packageType.zclXmlStandalone
16941735
)
16951736

1737+
// checking if any packages are on a different drive than the zap file (Windows only)
1738+
await validatePackagePathDrive(
1739+
db,
1740+
allPartitionPackages,
1741+
state.filePath,
1742+
sessionId
1743+
)
1744+
16961745
// Loading all packages before custom xml to make sure clusterExtensions are
16971746
// handled properly
16981747
let topLevelPackages = state.package.filter(

0 commit comments

Comments
 (0)