Unverified Commit 5ddc028c authored by David Hadka's avatar David Hadka Committed by GitHub
Browse files

Merge pull request #305 from actions/fix-upload-chunk

Fix upload chunk retries
parents ddc4681e e756b19f
Loading
Loading
Loading
Loading
+4 −5
Changes for dist/restore/index.js: 4 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -2326,7 +2326,7 @@ function getContentRange(start, end) {
    // Content-Range: bytes 0-199/*
    return `bytes ${start}-${end}/*`;
}
function uploadChunk(httpClient, resourceUrl, data, start, end) {
function uploadChunk(httpClient, resourceUrl, openStream, start, end) {
    return __awaiter(this, void 0, void 0, function* () {
        core.debug(`Uploading chunk of size ${end -
            start +
@@ -2336,7 +2336,7 @@ function uploadChunk(httpClient, resourceUrl, data, start, end) {
            "Content-Range": getContentRange(start, end)
        };
        const uploadChunkRequest = () => __awaiter(this, void 0, void 0, function* () {
            return yield httpClient.sendStream("PATCH", resourceUrl, data, additionalHeaders);
            return yield httpClient.sendStream("PATCH", resourceUrl, openStream(), additionalHeaders);
        });
        const response = yield uploadChunkRequest();
        if (isSuccessStatusCode(response.message.statusCode)) {
@@ -2379,13 +2379,12 @@ function uploadFile(httpClient, cacheId, archivePath) {
                    const start = offset;
                    const end = offset + chunkSize - 1;
                    offset += MAX_CHUNK_SIZE;
                    const chunk = fs.createReadStream(archivePath, {
                    yield uploadChunk(httpClient, resourceUrl, () => fs.createReadStream(archivePath, {
                        fd,
                        start,
                        end,
                        autoClose: false
                    });
                    yield uploadChunk(httpClient, resourceUrl, chunk, start, end);
                    }), start, end);
                }
            })));
        }
+4 −5
Changes for dist/save/index.js: 4 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -2326,7 +2326,7 @@ function getContentRange(start, end) {
    // Content-Range: bytes 0-199/*
    return `bytes ${start}-${end}/*`;
}
function uploadChunk(httpClient, resourceUrl, data, start, end) {
function uploadChunk(httpClient, resourceUrl, openStream, start, end) {
    return __awaiter(this, void 0, void 0, function* () {
        core.debug(`Uploading chunk of size ${end -
            start +
@@ -2336,7 +2336,7 @@ function uploadChunk(httpClient, resourceUrl, data, start, end) {
            "Content-Range": getContentRange(start, end)
        };
        const uploadChunkRequest = () => __awaiter(this, void 0, void 0, function* () {
            return yield httpClient.sendStream("PATCH", resourceUrl, data, additionalHeaders);
            return yield httpClient.sendStream("PATCH", resourceUrl, openStream(), additionalHeaders);
        });
        const response = yield uploadChunkRequest();
        if (isSuccessStatusCode(response.message.statusCode)) {
@@ -2379,13 +2379,12 @@ function uploadFile(httpClient, cacheId, archivePath) {
                    const start = offset;
                    const end = offset + chunkSize - 1;
                    offset += MAX_CHUNK_SIZE;
                    const chunk = fs.createReadStream(archivePath, {
                    yield uploadChunk(httpClient, resourceUrl, () => fs.createReadStream(archivePath, {
                        fd,
                        start,
                        end,
                        autoClose: false
                    });
                    yield uploadChunk(httpClient, resourceUrl, chunk, start, end);
                    }), start, end);
                }
            })));
        }
+9 −9
Changes for src/cacheHttpClient.ts: 9 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -206,7 +206,7 @@ function getContentRange(start: number, end: number): string {
async function uploadChunk(
    httpClient: HttpClient,
    resourceUrl: string,
    data: NodeJS.ReadableStream,
    openStream: () => NodeJS.ReadableStream,
    start: number,
    end: number
): Promise<void> {
@@ -227,7 +227,7 @@ async function uploadChunk(
        return await httpClient.sendStream(
            "PATCH",
            resourceUrl,
            data,
            openStream(),
            additionalHeaders
        );
    };
@@ -290,17 +290,17 @@ async function uploadFile(
                    const start = offset;
                    const end = offset + chunkSize - 1;
                    offset += MAX_CHUNK_SIZE;
                    const chunk = fs.createReadStream(archivePath, {
                        fd,
                        start,
                        end,
                        autoClose: false
                    });

                    await uploadChunk(
                        httpClient,
                        resourceUrl,
                        chunk,
                        () =>
                            fs.createReadStream(archivePath, {
                                fd,
                                start,
                                end,
                                autoClose: false
                            }),
                        start,
                        end
                    );