Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 520059b

Browse files
authored
Merge pull request #1938 from livecode/bugfix-extension_loading_error
[[ Bug 21082 ]] Ensure errors are thrown when failing to validate ext package
2 parents 8f2dee9 + f1529e5 commit 520059b

File tree

2 files changed

+16
-72
lines changed

2 files changed

+16
-72
lines changed

Toolset/libraries/revideextensionlibrary.livecodescript

Lines changed: 15 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -362,59 +362,27 @@ private command __extensionDownloadVerify pCacheIndex
362362
set the itemdel to "."
363363
if the last item of tExtensionPath is not "lce" then return __extensionError(pCacheIndex,"Could not install extension. The package extension '"&the last item of tExtensionPath&"' Is not valid. Must be 'lce'.")
364364

365-
# Get initial manifest data needed for loading
366-
local tManifestData, tManifestXMLTree
367-
put __extensionManifestData(pCacheIndex) into tManifestData
368-
put revXMLCreateTree(tManifestData,true,true,false) into tManifestXMLTree
369-
370-
# Check the manifest contains a name
371-
local tExtensionName
372-
put __extensionManifestValueFromTree(tManifestXMLTree, "name") into tExtensionName
365+
# Ensure the zip contains the things we expect
366+
local tManifestDataA
367+
extensionValidateLCEPackage tExtensionPath, tManifestDataA
373368
if the result is not empty then
374-
return __extensionError(pCacheIndex,"Could not install extension. The package manifest must contain a valid name (com.livecode.extensions.<developer_ID>.<extension_name>)")
375-
end if
376-
__extensionPropertySet pCacheIndex, "name", tExtensionName
377-
378-
# Check the manifest contains a version
379-
local tExtensionVersion
380-
put __extensionManifestValueFromTree(tManifestXMLTree, "version") into tExtensionVersion
381-
if the result is not empty then
382-
return __extensionError(pCacheIndex,"Could not install extension. The package manifest must contain a valid version number (1.2.3 - major,minor,maintenance)")
383-
end if
384-
__extensionPropertySet pCacheIndex, "version", tExtensionVersion
385-
386-
# Check the manifest contains an author
387-
local tExtensionAuthor
388-
put __extensionManifestValueFromTree(tManifestXMLTree, "author") into tExtensionAuthor
389-
if the result is not empty then
390-
return __extensionError(pCacheIndex,"Could not install extension. The package manifest must contain an author")
391-
end if
392-
__extensionPropertySet pCacheIndex, "author", tExtensionAuthor
393-
394-
# Check the manifest contains an type
395-
local tExtensionType
396-
put __extensionManifestValueFromTree(tManifestXMLTree, "type") into tExtensionType
397-
if the result is not empty then
398-
return __extensionError(pCacheIndex,"Could not install extension. The package manifest must contain a type")
399-
end if
400-
__extensionPropertySet pCacheIndex, "type", tExtensionType
401-
402-
# Check the manifest contains an title
403-
local tExtensionTitle
404-
put __extensionManifestValueFromTree(tManifestXMLTree, "title") into tExtensionTitle
405-
if the result is not empty then
406-
return __extensionError(pCacheIndex,"Could not install extension. The package manifest must contain a title")
369+
return the result
407370
end if
408-
__extensionPropertySet pCacheIndex, "title", tExtensionTitle
409371

410-
revXMLDeleteTree tManifestXMLTree
372+
repeat for each key tKey in tManifestDataA
373+
__extensionPropertySet pCacheIndex, tKey, tManifestDataA[tKey]
374+
end repeat
411375

412376
# Build the type ID from the name and version
413-
__extensionPropertySet pCacheIndex, "type_id", tExtensionName & "." & tExtensionVersion
377+
__extensionPropertySet pCacheIndex, "type_id", \
378+
tManifestDataA["name"] & "." & tManifestDataA["version"]
414379
end __extensionDownloadVerify
415380

416381
private command __extensionInstall pCacheIndex, pPackage, pFromStore
417382
__extensionDownloadVerify pCacheIndex
383+
if the result is not empty then
384+
throw "Error installing extension" && pPackage & return & the result
385+
end if
418386

419387
local tName, tTypeId, tInstallPath
420388
put __extensionPropertyGet(pCacheIndex, "name") into tName
@@ -497,6 +465,9 @@ end __extensionInstallCopyInterfaceFile
497465
private command __extensionInstallLoad pCacheIndex, pName, pInstallFolder, pProgress
498466
local tFolderData
499467
extensionFindInFolder pInstallFolder, true, false, tFolderData
468+
if tFolderData is empty then
469+
throw "extension missing from" && pInstallFolder
470+
end if
500471

501472
local tDataA
502473
put tFolderData[pName][pInstallFolder] into tDataA["copies"][1]
@@ -1346,34 +1317,6 @@ private function __extensionManifestValueFromTree pTreeID, pProperty
13461317
return tValue for value
13471318
end __extensionManifestValueFromTree
13481319

1349-
private function __extensionManifestData pCacheIndex
1350-
# Get the path to the package file
1351-
local tExtensionPackageFile
1352-
put __extensionPropertyGet(pCacheIndex, "download_package_path") into tExtensionPackageFile
1353-
1354-
if not there is a file tExtensionPackageFile then return __extensionError(pCacheIndex,"Could not extract manifest because package was not found in downloads folder")
1355-
1356-
# A zip can come compressed with a base folder or without. So work out what the
1357-
# root folder is before trying to extract files
1358-
revZipOpenArchive tExtensionPackageFile, "read"
1359-
1360-
local tZipItems, tZipRoot
1361-
put revZipEnumerateItems(tExtensionPackageFile) into tZipItems
1362-
1363-
if the last char of line 1 of tZipItems is "/" then
1364-
put line 1 of tZipItems into tZipRoot
1365-
else
1366-
put empty into tZipRoot
1367-
end if
1368-
1369-
# Extract the package manfiest to a variable to read key data
1370-
local tManifestData, tManifestXMLTree, tValue
1371-
revZipExtractItemToVariable tExtensionPackageFile, (tZipRoot & "manifest.xml"), "tManifestData"
1372-
1373-
revZipCloseArchive tExtensionPackageFile
1374-
return tManifestData
1375-
end __extensionManifestData
1376-
13771320
function __extensionSampleStacks pID, pFolder
13781321
local tSampleFolder, tSamples, tSampleArray
13791322

notes/bugfix-21082.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Notify when attempting to install package that doesn't validate

0 commit comments

Comments
 (0)