mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-19 21:14:44 +08:00
These scripts check if a file exists and whether its content is different from a source file before copying it. However the file look up done with fs.existsSync() could be case-insensitive depending on the underlying file system. This CL implements the a case-sensitive file look up to compare against the exact path name of the file being copied. Bug: none Change-Id: I0dc175c2292b3caea541a585562e8e25db637340 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3256666 Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org> Commit-Queue: Andres Olivares <andoli@chromium.org>
36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
// Copyright 2020 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const [, , src, dest] = process.argv;
|
|
|
|
const srcPath = path.join(process.cwd(), src);
|
|
const destPath = path.join(process.cwd(), dest);
|
|
|
|
// If there's a file there from a previous build, unlink it first. This
|
|
// is because the file in that location might be a hardlinked file, and
|
|
// overwriting it doesn't change the fact that it's hardlinked.
|
|
const srcContents = fs.readFileSync(srcPath);
|
|
if (fileExists(destPath)) {
|
|
// Check contents, return early if match
|
|
const destContents = fs.readFileSync(destPath);
|
|
if (srcContents.equals(destContents)) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Force a write to the target filesystem, since by default the ninja
|
|
// toolchain will create a hardlink, which in turn reflects changes in
|
|
// gen and resources/inspector back to //front_end.
|
|
fs.writeFileSync(destPath, srcContents);
|
|
|
|
/**
|
|
* Case sensitive implementation of a file look up.
|
|
*/
|
|
function fileExists(filePath) {
|
|
const dir = path.dirname(filePath);
|
|
const files = fs.readdirSync(dir);
|
|
return files.includes(path.basename(filePath));
|
|
}
|