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

Commit e028300

Browse files
Merge pull request #1945 from livecode/bugfix-extension_dependencies
[[ Extensions ]] Detect missing dependencies when installing package
2 parents 1c17196 + 5da25b6 commit e028300

File tree

1 file changed

+78
-69
lines changed

1 file changed

+78
-69
lines changed

Toolset/libraries/revideextensionlibrary.livecodescript

Lines changed: 78 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,55 @@ command revIDEExtensionDownloadAndInstall pExtensionPath, pType, pCallbackObject
7878
__extensionsChanged
7979
end revIDEExtensionDownloadAndInstall
8080

81-
command revIDEExtensionInstall pPackageLocation
81+
private function __extensionDependencyExists pExt
82+
return __extensionCacheID("name", pExt) is a number
83+
end __extensionDependencyExists
84+
85+
private command __extensionInstallPackage pPackageLocation
8286
if there is not a file pPackageLocation then
83-
answer error "No package found at" && pPackageLocation
84-
exit revIDEExtensionInstall
87+
throw "No package found at" && pPackageLocation
8588
end if
8689

87-
local tCacheIndex, tFromStore
90+
local tCacheIndex
8891
put __extensionCacheID("download_package_path", pPackageLocation) \
8992
into tCacheIndex
9093
if tCacheIndex is not a number then
91-
-- Direct install from package file
92-
put false into tFromStore
9394
put the number of elements of sExtensions + 1 into tCacheIndex
9495
__extensionPropertySet tCacheIndex, "download_package_path", pPackageLocation
95-
else
96-
put true into tFromStore
96+
__extensionUpdateUIWithPackage tCacheIndex, pPackageLocation
9797
end if
98+
__extensionPropertySet tCacheIndex, "status", "installing"
99+
100+
local tVerifyResult, tName
101+
__extensionDownloadVerify tCacheIndex
102+
put the result into tVerifyResult
103+
if tVerifyResult is not empty then
104+
__extensionCacheRemove tCacheIndex
105+
throw "Error installing extension" && pPackageLocation & return & the result
106+
end if
107+
108+
put __extensionPropertyGet(tCacheIndex, "name") into tName
98109

110+
# Fetch the dependency list (minus builtin modules) and ensure all
111+
# are loaded
112+
local tDeps
113+
put revIDEExtensionsOrderByDependency(tName) into tDeps
114+
repeat for each line tExtension in tDeps
115+
# Skip the one we're installing
116+
if tExtension is tName then
117+
next repeat
118+
end if
119+
# Ensure dependency exists
120+
if not __extensionDependencyExists(tExtension) then
121+
throw "Dependency" && tExtension && "not available. Please install before proceeding"
122+
end if
123+
end repeat
124+
__extensionInstall tCacheIndex, pPackageLocation
125+
end __extensionInstallPackage
126+
127+
command revIDEExtensionInstall pPackageLocation
99128
try
100-
__extensionInstall tCacheIndex, pPackageLocation, tFromStore
129+
__extensionInstallPackage pPackageLocation
101130
catch tError
102131
answer error tError
103132
end try
@@ -288,14 +317,32 @@ private command __extensionDownloadBegin pExtensionUrl, pType, pCallbackObject,
288317
return tCacheIndex for value
289318
end __extensionDownloadBegin
290319

320+
private command __extensionUpdateUIWithPackage pCacheIndex, pPath
321+
# Get initial name from file
322+
set the itemdel to "."
323+
local tName
324+
put pPath into tName
325+
delete the last item of tName
326+
repeat while the last item of tName is a number
327+
delete the last item of tName
328+
end repeat
329+
__extensionPropertySet pCacheIndex, "name", tName
330+
331+
# Send update to refresh UI with new package installation
332+
doExtensionsChanged
333+
end __extensionUpdateUIWithPackage
334+
291335
# Download the extension
292336
private command __extensionDownload pCacheIndex
293337
# Check the file extension is correct
294338
local tURL
295339
put __extensionPropertyGet(pCacheIndex,"package_url") into tURL
296340

297341
set the itemdel to "."
298-
if the last item of tURL is not "lce" then return __extensionError(pCacheIndex,"Could not download extension. The package must have the file extension 'lce':" && tURL)
342+
if the last item of tURL is not "lce" then
343+
return __extensionError(pCacheIndex, \
344+
"The package must have the file extension 'lce':" && tURL)
345+
end if
299346

300347
local tPackageFilePath
301348
set the itemdel to "/"
@@ -306,19 +353,9 @@ private command __extensionDownload pCacheIndex
306353
__extensionPropertySet pCacheIndex, "progress_message", "Downloading"
307354
__extensionPropertySet pCacheIndex, "progress", 0
308355
__extensionPropertySet pCacheIndex, "label", tPackageFilePath
356+
__extensionPropertySet pCacheIndex, "downloaded_from_store", true
309357

310-
# Put is a first stab at the name
311-
set the itemdel to "."
312-
local tName
313-
put tPackageFilePath into tName
314-
delete the last item of tName
315-
repeat while the last item of tName is a number
316-
delete the last item of tName
317-
end repeat
318-
__extensionPropertySet pCacheIndex, "name", tName
319-
320-
# Send update to refresh UI with new package installation
321-
__extensionsChanged
358+
__extensionUpdateUIWithPackage pCacheIndex, tPackageFilePath
322359

323360
# Update progress
324361
__extensionSendProgressUpdate pCacheIndex, "Downloading", 0
@@ -356,11 +393,18 @@ private command __extensionDownloadVerify pCacheIndex
356393
put __extensionPropertyGet(pCacheIndex, "download_package_path") into tExtensionPath
357394

358395
# Check the package exists
359-
if there is not a file tExtensionPath then return __extensionError(pCacheIndex,"Could not install extension. Package does not exists: " && tExtensionPath)
396+
if there is not a file tExtensionPath then
397+
return __extensionError(pCacheIndex, \
398+
"Package does not exist: " && tExtensionPath)
399+
end if
360400

361401
# Check the file extension is valid
362402
set the itemdel to "."
363-
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'.")
403+
if the last item of tExtensionPath is not "lce" then
404+
return __extensionError(pCacheIndex, "The package extension '" & \
405+
the last item of tExtensionPath&"' is not valid." && \
406+
" Must be 'lce'.")
407+
end if
364408

365409
# Ensure the zip contains the things we expect
366410
local tManifestDataA
@@ -378,12 +422,7 @@ private command __extensionDownloadVerify pCacheIndex
378422
tManifestDataA["name"] & "." & tManifestDataA["version"]
379423
end __extensionDownloadVerify
380424

381-
private command __extensionInstall pCacheIndex, pPackage, pFromStore
382-
__extensionDownloadVerify pCacheIndex
383-
if the result is not empty then
384-
throw "Error installing extension" && pPackage & return & the result
385-
end if
386-
425+
private command __extensionInstall pCacheIndex, pPackage
387426
local tName, tTypeId, tInstallPath
388427
put __extensionPropertyGet(pCacheIndex, "name") into tName
389428
put __extensionPropertyGet(pCacheIndex, "type_id") into tTypeId
@@ -394,7 +433,7 @@ private command __extensionInstall pCacheIndex, pPackage, pFromStore
394433
__extensionInstallExtract pCacheIndex, tInstallPath, tTypeID, pPackage, 30
395434
__extensionInstallCopyInterfaceFile pCacheIndex, tName, tInstallPath, 50
396435
__extensionInstallLoad pCacheIndex, tName, tInstallPath, 80
397-
__extensionInstallFinalise pCacheIndex, tTypeID, pFromStore
436+
__extensionInstallFinalise pCacheIndex, tTypeID
398437
end __extensionInstall
399438

400439
on __extensionInstallRemoveOlderVersions pCacheIndex, pName, pProgress
@@ -491,9 +530,9 @@ private command __extensionInstallLoad pCacheIndex, pName, pInstallFolder, pProg
491530
end __extensionInstallLoad
492531

493532
# Delete installation files and original package
494-
on __extensionInstallFinalise pCacheIndex, pTypeId, pDeletePackage
533+
on __extensionInstallFinalise pCacheIndex, pTypeId
495534
# Delete temp package file
496-
if pDeletePackage then
535+
if __extensionPropertyGet(pCacheIndex, "downloaded_from_store") then
497536
# Update progress
498537
__extensionSendProgressUpdate pCacheIndex, "Removing temp files", 90
499538
local tTempInstallPackage
@@ -763,10 +802,9 @@ private command __extensionSetPropertyInfoFromManifest pID, pManifest
763802
put tPropertyInfo into sExtensionProperties[pID]
764803
end __extensionSetPropertyInfoFromManifest
765804

766-
private command __extensionError pCacheIndex, pErrorMessage
805+
private function __extensionError pCacheIndex, pErrorMessage
767806
__extensionSendProgressUpdate pCacheIndex, "Error:" && pErrorMessage, 100
768-
throw pErrorMessage
769-
return empty
807+
return pErrorMessage
770808
end __extensionError
771809

772810
# Send notication that widget has been added/removed
@@ -901,6 +939,10 @@ private function __extensionCacheID pPropertyToSearch, pValue
901939
end repeat
902940
end __extensionCacheID
903941

942+
private command __extensionCacheRemove pIndex
943+
delete variable sExtensions[pIndex]
944+
end __extensionCacheRemove
945+
904946
# Gets a property from the internal extension cache
905947
function __extensionPropertyGet pCacheIndex, pProperty
906948
return sExtensions[pCacheIndex][pProperty]
@@ -1285,39 +1327,6 @@ function revIDEExtensionFetchDefaultScript pFolder, pCacheIndex, pValidate
12851327
return tScript
12861328
end revIDEExtensionFetchDefaultScript
12871329

1288-
private function __extensionManifestValueFromTree pTreeID, pProperty
1289-
local tValue
1290-
switch pProperty
1291-
case "requires"
1292-
# Fetch extension dependencies
1293-
local tRequires, tCount
1294-
put 0 into tCount
1295-
put revXMLChildNames(pTreeID,"package",return,"requires",true) into tRequires
1296-
if tRequires begins with "xmlerr" then
1297-
put tRequires into tValue
1298-
break
1299-
end if
1300-
repeat for each line tDependency in tRequires
1301-
add 1 to tCount
1302-
local tName
1303-
put revXMLAttribute(pTreeID,"package" & "/" & tDependency,"name") into tName
1304-
if tName begins with "xmlerr" then
1305-
put tName into tValue
1306-
break
1307-
end if
1308-
put tName into tValue[tCount]
1309-
end repeat
1310-
default
1311-
put revXMLNodeContents(pTreeID,"/package/" & pProperty) into tValue
1312-
break
1313-
end switch
1314-
1315-
if tValue begins with "xmlerr" then
1316-
return tValue for error
1317-
end if
1318-
return tValue for value
1319-
end __extensionManifestValueFromTree
1320-
13211330
function __extensionSampleStacks pID, pFolder
13221331
local tSampleFolder, tSamples, tSampleArray
13231332

0 commit comments

Comments
 (0)