Skip to content

Commit 83a1f09

Browse files
author
Barthélémy Ledoux
authored
fix: warn when the projectRoot is not writeable (#18495)
closes #18485
1 parent af472b6 commit 83a1f09

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

packages/server/lib/modes/run.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,22 @@ const openProjectCreate = (projectRoot, socketId, args) => {
608608
return openProject.create(projectRoot, args, options)
609609
}
610610

611-
const createAndOpenProject = async function (socketId, options) {
611+
async function checkAccess (folderPath) {
612+
return fs.access(folderPath, fs.W_OK).catch((err) => {
613+
if (['EACCES', 'EPERM'].includes(err.code)) {
614+
// we cannot write due to folder permissions
615+
return errors.warning('FOLDER_NOT_WRITABLE', folderPath)
616+
}
617+
618+
throw err
619+
})
620+
}
621+
622+
const createAndOpenProject = async (socketId, options) => {
612623
const { projectRoot, projectId } = options
613624

625+
await checkAccess(projectRoot)
626+
614627
return openProjectCreate(projectRoot, socketId, options)
615628
.then((open_project) => open_project.getProject())
616629
.then((project) => {

packages/server/test/e2e/non_root_read_only_fs_spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ describe('e2e readonly fs', function () {
88

99
const projectPath = Fixtures.projectPath('read-only-project-root')
1010

11+
/**
12+
* Change permissions recursively
13+
*/
1114
const chmodr = (p: string, mode: number) => {
1215
const stats = fs.statSync(p)
1316

packages/server/test/unit/modes/run_spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ describe('lib/modes/run', () => {
662662
sinon.stub(random, 'id').returns(1234)
663663
sinon.stub(openProject, 'create').resolves(openProject)
664664
sinon.stub(runMode, 'waitForSocketConnection').resolves()
665+
sinon.stub(fs, 'access').resolves()
665666
sinon.stub(runMode, 'waitForTestsToFinishRunning').resolves({
666667
stats: { failures: 10 },
667668
spec: {},
@@ -736,6 +737,7 @@ describe('lib/modes/run', () => {
736737

737738
sinon.stub(electron.app, 'on').withArgs('ready').yieldsAsync()
738739
sinon.stub(user, 'ensureAuthToken')
740+
sinon.stub(fs, 'access').resolves()
739741
sinon.stub(random, 'id').returns(1234)
740742
sinon.stub(openProject, 'create').resolves(openProject)
741743
sinon.stub(system, 'info').resolves({ osName: 'osFoo', osVersion: 'fooVersion' })

0 commit comments

Comments
 (0)