Skip to content

Commit 1ee481b

Browse files
committed
fix size fetching *shrug*
1 parent 3d846bf commit 1ee481b

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/main/scala/MakeDownloadPage.scala

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import scala.concurrent.*
44
import scala.concurrent.duration.*
55
import ExecutionContext.Implicits.global
66
import java.nio.file.{Files, Paths}
7+
import scala.collection.mutable.ListBuffer
78

89
class MakeDownloadPage(version: String, releaseDate: Date = new Date()):
910
def write() =
@@ -14,11 +15,15 @@ class MakeDownloadPage(version: String, releaseDate: Date = new Date()):
1415
println("# to prepare your scala-lang PR")
1516

1617
// get size of `url` without actually downloading it
17-
def humanSize(url: String): Future[String] = Future:
18+
def humanSize(url: String): Future[String] =
1819
import scala.sys.process.*
1920
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
2227
val contentLength = responseHeader.map(_.toLowerCase).filter(_.startsWith("content-length"))
2328
val bytes = contentLength.map(_.split(":",2)(1).trim.toInt).maxOption // maxOption handles redirects
2429
bytes map (b => (responseHeader.head, b))
@@ -31,10 +36,12 @@ class MakeDownloadPage(version: String, releaseDate: Date = new Date()):
3136
humanSize
3237
case _ =>
3338
println(s"## warning: could not fetch $url")
39+
println(err.toString)
3440
""
41+
Future(r)
3542

3643
def isGoodStatus(status: String): Boolean =
37-
Seq("200 OK", "302 found", "HTTP/2 200").exists(status.contains)
44+
Seq("200", "302").exists(status.contains)
3845

3946
def resourceArchive(cls: String, name: String, ext: String, desc: String): Future[String] =
4047
val fileName = s"$name-$version.$ext"

0 commit comments

Comments
 (0)