Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #loop until FULL_FILE is set in fetch_blob.. this is for bad/slow connections
  2. while [ "$FULL_FILE" != "1" ];do
  3. local token="$(curl -fsSL "$authBase/token?service=$authService&scope=repository:$image:pull" | jq --raw-output '.token')"
  4. fetch_blob "$token" "$image" "$layerDigest" "$dir/$layerTar" --progress
  5. sleep 1
  6. done
  7.  
  8. while :; do
  9. #if the file already exists.. we will be resuming..
  10. if [ -f "$targetFile" ];then
  11. #getting current size of file we are resuming
  12. CUR=`stat --printf="%s" $targetFile`
  13. #use curl to get headers to find content-length of the full file
  14. LEN=`curl -I -fL "${curlArgs[@]}" "$blobRedirect"|grep content-length|cut -d" " -f2`
  15.  
  16. #if we already have the entire file... lets stop curl from erroring with 416
  17. if [ "$CUR" == "${LEN//[!0-9]/}" ]; then
  18. FULL_FILE=1
  19. break
  20. fi
  21. fi
  22.  
  23. HTTP_CODE=`curl -w %{http_code} -C - --tr-encoding --compressed --progress-bar -fL "${curlArgs[@]}" "$blobRedirect" -o "$targetFile"`
  24. if [ "$HTTP_CODE" == "403" ]; then
  25. #token expired so the server stopped allowing us to resume, lets return without setting FULL_FILE and itll restart this func w new token
  26. FULL_FILE=0
  27. break
  28. fi
  29.  
  30. if [ "$HTTP_CODE" == "416" ]; then
  31. FULL_FILE=1
  32. break
  33. fi
  34.  
  35. sleep 1
  36. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement