@@ -4,6 +4,7 @@ import scala.concurrent.*
4
4
import scala .concurrent .duration .*
5
5
import ExecutionContext .Implicits .global
6
6
import java .nio .file .{Files , Paths }
7
+ import scala .collection .mutable .ListBuffer
7
8
8
9
class MakeDownloadPage (version : String , releaseDate : Date = new Date ()):
9
10
def write () =
@@ -14,11 +15,15 @@ class MakeDownloadPage(version: String, releaseDate: Date = new Date()):
14
15
println(" # to prepare your scala-lang PR" )
15
16
16
17
// get size of `url` without actually downloading it
17
- def humanSize (url : String ): Future [String ] = Future :
18
+ def humanSize (url : String ): Future [String ] =
18
19
import scala .sys .process .*
19
20
println(" ## fetching size of " + url)
20
- scala.util.Try {
21
- val responseHeader = Process (s " curl -L -m 5 --silent -D - -X HEAD $url" ).lazyLines
21
+ val out = ListBuffer .empty[String ]
22
+ val err = StringBuilder ()
23
+ val r = scala.util.Try {
24
+ val logger = ProcessLogger (out += _, e => err.append(e + " \n " ))
25
+ Process (s " curl -L -m 5 --silent -D - -X HEAD $url" ).! (logger)
26
+ val responseHeader = out.toList
22
27
val contentLength = responseHeader.map(_.toLowerCase).filter(_.startsWith(" content-length" ))
23
28
val bytes = contentLength.map(_.split(" :" ,2 )(1 ).trim.toInt).maxOption // maxOption handles redirects
24
29
bytes map (b => (responseHeader.head, b))
@@ -31,10 +36,12 @@ class MakeDownloadPage(version: String, releaseDate: Date = new Date()):
31
36
humanSize
32
37
case _ =>
33
38
println(s " ## warning: could not fetch $url" )
39
+ println(err.toString)
34
40
" "
41
+ Future (r)
35
42
36
43
def isGoodStatus (status : String ): Boolean =
37
- Seq (" 200 OK " , " 302 found " , " HTTP/2 200 " ).exists(status.contains)
44
+ Seq (" 200" , " 302" ).exists(status.contains)
38
45
39
46
def resourceArchive (cls : String , name : String , ext : String , desc : String ): Future [String ] =
40
47
val fileName = s " $name- $version. $ext"
0 commit comments