Skip to content

Commit

Permalink
fix(core): drop file lock after its used (#20165)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored Nov 10, 2023
1 parent d899abe commit c04fa3a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
2 changes: 2 additions & 0 deletions packages/nx/bin/post-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
26 changes: 9 additions & 17 deletions packages/nx/src/native/workspace/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,26 @@ 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 {
trace!("waiting for files");
cvar.wait(&mut files);
}

let cloned_files = files.clone();
drop(files);

trace!("files are available");
Some(files)
Some(cloned_files)
}

pub fn update_files(
Expand Down Expand Up @@ -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]
Expand All @@ -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,
)
}
Expand Down

0 comments on commit c04fa3a

Please sign in to comment.