Skip to content

Commit

Permalink
Fix Run.copyFile not to read an entire file into memory (#1041)
Browse files Browse the repository at this point in the history
esy-build-package: fix Run.copyFile not to read entire file in memory

Also fix slowtest detection on azure.

Co-authored-by: Ulrik Strid <ulrik.strid@outlook.com>
  • Loading branch information
andreypopp and ulrikstrid committed Jan 12, 2020
2 parents ec3cde7 + 450fd79 commit a988a1a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
23 changes: 21 additions & 2 deletions esy-build-package/Run.re
Expand Up @@ -129,8 +129,27 @@ let write = (~perm=?, ~data, path) =>
let read = path => Bos.OS.File.read(path);

let copyFile = (~perm=?, srcPath, dstPath) => {
let%bind data = read(srcPath);
write(~data, ~perm?, dstPath);
// Choosen "arbitrarily" but informed by:
// https://eklitzke.org/efficient-file-copying-on-linux
let buflen = 1024 * 128;
let buf = Bytes.create(buflen);
let rec loop = (ic, oc, ()) => {
switch (input(ic, buf, 0, buflen)) {
| 0 => return()
| n =>
output(oc, buf, 0, n);
loop(ic, oc, ());
};
};
let%bind res =
Bos.OS.File.with_ic(
srcPath,
(ic, ()) =>
Bos.OS.File.with_oc(~mode=?perm, dstPath, oc => loop(ic, oc), ()),
(),
);
let%bind res = res;
res;
};

let mv = Bos.OS.Path.move;
Expand Down
6 changes: 4 additions & 2 deletions test-e2e-slow/run-slow-tests.js
Expand Up @@ -5,7 +5,7 @@ const os = require('os');

// this is required so esy won't "attach" to the outer esy project (esy
// itself)
delete process.env.ESY__ROOT_PACKAGE_CONFIG_PATH
delete process.env.ESY__ROOT_PACKAGE_CONFIG_PATH;

const isTaggedCommit = () => {
const TRAVIS_TAG = process.env['TRAVIS_TAG'];
Expand All @@ -19,11 +19,14 @@ const isTaggedCommit = () => {
const getCommitMessage = () => {
const TRAVIS_COMMIT_MESSAGE = process.env['TRAVIS_COMMIT_MESSAGE'];
const APPVEYOR_REPO_COMMIT_MESSAGE = process.env['APPVEYOR_REPO_COMMIT_MESSAGE'];
const AZURE_COMMIT_MESSAGE = process.env['Build.SourceVersionMessage'];

if (TRAVIS_COMMIT_MESSAGE) {
return TRAVIS_COMMIT_MESSAGE;
} else if (APPVEYOR_REPO_COMMIT_MESSAGE) {
return APPVEYOR_REPO_COMMIT_MESSAGE;
} else if (AZURE_COMMIT_MESSAGE) {
return AZURE_COMMIT_MESSAGE;
} else {
return execSync('git log -n1').toString('utf8');
}
Expand Down Expand Up @@ -66,4 +69,3 @@ if (!isWindows) {
require('./esy-npm-release/legacy.test.js');
}
require('./esy-npm-release/no-rewrite.test.js');

0 comments on commit a988a1a

Please sign in to comment.