Prefetch and __Download and file existence

Hi,
I am trying to avoid unnecessary downloads by checking if file is already exist and correct SHA1.
I can see interesting behavior by client due to prefetch block
Does prefetch reset __Download folder of site every time ?
Let me know if this is obvious , I’m not recollecting __Download behavior
Can you suggest on this limitation ?

Before Adding prefetch block –

/ / Enter your action script here
parameter “PackageBinary” = "WIN_CIAP_TEST_1_0.zip"
parameter “Binaryfile” = "{pathname of client folder of current site}__Download{parameter “PackageBinary”}"
parameter “packageType” =“OnDemand”

if { exist files (parameter "Binaryfile") whose (sha1 of it = "483f33998a5456e0ea8bc94b6c8df5c34c149a4b" and size of it =  71554)}
        parameter "downloadRequired" = "NO"
else
        parameter "downloadRequired" = "YES"
        if {(parameter "packageType") = "OnDemand"}
               setting "_BESClient_Download_Direct"="1" on "{now}" for client
               download now {parameter "DownloadURL"} 
               setting "_BESClient_Download_Direct"="0" on "{now}" for client  
        else
               download now {parameter "DownloadURL"}
        endif
endif

Relevant - WIN_DownloadExist_File_1_0 (fixlet:142065)
At 17:43:06 -0500 -
ActionLogMessage: (action:142065) Action signature verified for Execution
ActionLogMessage: (action:142065) starting action
At 17:43:06 -0500 - actionsite (http://bigfixdev.nam.nsroot.net:52311/cgi-bin/bfgather.exe/actionsite)
Command succeeded parameter “PackageBinary” = “WIN_CIAP_TEST_1_0.zip” (action:142065)
Command succeeded parameter “Binaryfile” = “C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\CustomSite_WIN_Software__Download\WIN_CIAP_TEST_1_0.zip” (action:142065)
Command succeeded parameter “packageType” =“OnDemand” (action:142065)
Command succeeded parameter “downloadRequired” = “NO” (action:142065)

After Adding prefetch block –

                    // Download tools
begin prefetch block 
       parameter "downloadUtilities"="{pathname of file "downloadUtilities.spec" of client folder of site "CustomSite_WIN_Software"}"
       add prefetch item {concatenation ";" of lines of file (parameter "downloadUtilities")}
end prefetch block 


// Enter your action script here
parameter "PackageBinary" = "WIN_CIAP_TEST_1_0.zip"
parameter "Binaryfile" = "{pathname of client folder of current site}\__Download\{parameter "PackageBinary"}"
parameter "packageType" ="OnDemand"


if { exist files (parameter "Binaryfile") whose (sha1 of it = "483f33998a5456e0ea8bc94b6c8df5c34c149a4b" and size of it =  71554)}
parameter "downloadRequired" = "NO"
else
parameter "downloadRequired" = "YES"
if {(parameter "packageType") = "OnDemand"}
       setting "_BESClient_Download_Direct"="1" on "{now}" for client
       download now {parameter "DownloadURL"} 
       setting "_BESClient_Download_Direct"="0" on "{now}" for client  
else
       download now {parameter "DownloadURL"}
endif
endif

Result
ActionLogMessage: (action:142068) Action signature verified for Downloads
ActionLogMessage: (action:142068) Non-Distributed - DownloadsAvailable
ActionLogMessage: (action:142068) Action signature verified for Execution
ActionLogMessage: (action:142068) starting action
At 17:44:26 -0500 - actionsite (http://bigfixdev.nam.nsroot.net:52311/cgi-bin/bfgather.exe/actionsite)
Command succeeded parameter “downloadUtilities”=“C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\CustomSite_WIN_Software\downloadUtilities.spec” (action:142068)
Command succeeded parameter “PackageBinary” = “WIN_CIAP_TEST_1_0.zip” (action:142068)
Command succeeded parameter “Binaryfile” = “C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\CustomSite_WIN_Software__Download\WIN_CIAP_TEST_1_0.zip” (action:142068)
Command succeeded parameter “packageType” =“OnDemand” (action:142068)
Command succeeded parameter “downloadRequired” = “YES” (action:142068)
Command succeeded setting “_BESClient_Download_Direct”=“1” on “Fri, 26 Jan 2018 17:44:26 -0500” for client (action:142068)

strong text

The __Download directory is emptied when an action begins and is populated with the downloads for the action. This is why you can get into a state if you are still running something from a previous action from that directory and it cannot delete the files.

The prefetch block can slightly change the behaviour as some of this is done when the action has begun instead of prior to the start of the action.

The other issue is that relying on items checking the downloads is not reliable with if conditions as the flow through the actionscript is determined before the action starts as the downloads need to be determined at that earlier stage. Your download now commands are probably always going to run and also setting {now} on the setting is not the best practice but might be applicable here… but also this will affect later downloads.

How can I avoid multiple downloads when same fixlet is getting run on same machine ?
Every time it will download contents which is unnecessary.
I have contents which is large in size , sometime in gigabytes.

The easiest way is to increase the cache size on the endpoint, and use standard ‘prefetch’ statements. As long as the cache size isn’t exceeded, the download won’t be cleared.

We do have a separate cache called the utility cache that could be used. It is intended to store downloads that are used frequently (usually across different actions), so they don’t need to be downloaded repeatedly. Typically these are smaller files, but if the use case fits that intention, then it would be appropriate. Take a look at this post for details: https://forum.bigfix.com/t/utility-action-how-does-it-work/9637

1 Like

Perfect … Now I am satisfied with Bigfix Agent behavior as it needs to maintain the cache size.
Yes , I know utility cache.

thanks