fix(core): drop file lock after its used (#20165)

This commit is contained in:
Jason Jean 2023-11-10 00:02:23 -05:00 committed by GitHub
parent d899abe7f4
commit c04fa3ad5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 17 deletions

View File

@ -8,9 +8,11 @@ import { verifyOrUpdateNxCloudClient } from '../src/nx-cloud/update-manager';
import { getCloudOptions } from '../src/nx-cloud/utilities/get-cloud-options';
import { isNxCloudUsed } from '../src/utils/nx-cloud-utils';
import { readNxJson } from '../src/config/nx-json';
import { setupWorkspaceContext } from '../src/utils/workspace-context';
(async () => {
try {
setupWorkspaceContext(workspaceRoot);
if (isMainNxPackage() && fileExists(join(workspaceRoot, 'nx.json'))) {
const b = new Date();
assertSupportedPlatform();

View File

@ -65,13 +65,14 @@ impl FilesWorker {
FilesWorker(Some(files_lock))
}
pub fn get_files(&self) -> Option<MutexGuard<'_, RawMutex, Files>> {
pub fn get_files(&self) -> Option<Vec<(PathBuf, String)>> {
let Some(files_sync) = &self.0 else {
trace!("there were no files because the workspace root did not exist");
return None;
};
let (files_lock, cvar) = &files_sync.deref();
trace!("locking files");
let mut files = files_lock.lock();
let files_len = files.len();
if files_len == 0 {
@ -79,8 +80,11 @@ impl FilesWorker {
cvar.wait(&mut files);
}
let cloned_files = files.clone();
drop(files);
trace!("files are available");
Some(files)
Some(cloned_files)
}
pub fn update_files(
@ -156,22 +160,13 @@ impl WorkspaceContext {
workspace_files::get_files(
globs,
parse_configurations,
self.files_worker
.get_files()
.as_deref()
.map(|files| files.as_slice()),
self.files_worker.get_files().as_deref(),
)
}
#[napi]
pub fn glob(&self, globs: Vec<String>) -> napi::Result<Vec<String>, WorkspaceErrors> {
config_files::glob_files(
globs,
self.files_worker
.get_files()
.as_deref()
.map(|files| files.as_slice()),
)
config_files::glob_files(globs, self.files_worker.get_files().as_deref())
}
#[napi]
@ -185,10 +180,7 @@ impl WorkspaceContext {
{
config_files::get_project_configurations(
globs,
self.files_worker
.get_files()
.as_deref()
.map(|files| files.as_slice()),
self.files_worker.get_files().as_deref(),
parse_configurations,
)
}