Skip to content

Commit

Permalink
Fix random profile corruption with multiple windows are opened
Browse files Browse the repository at this point in the history
  • Loading branch information
cavearr committed Oct 22, 2024
1 parent c9da868 commit 6e929b0
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"node": true,
"esversion": 8,
"node": true,
"browser": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "icestudio",
"flavour": "develop",
"version": "0.12.1w",
"version": "0.12.2w",
"description": "Visual editor for open FPGA boards",
"contributors": [
{
Expand Down
5 changes: 4 additions & 1 deletion app/scripts/factories/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ angular.module('icestudio')
.factory('sparkMD5', function() {
return require('spark-md5');
})

.factory('fsLock',function(){
return require ('proper-lockfile');
})

.factory('nodeFs', function() {
return require('fs');
})
Expand Down
34 changes: 32 additions & 2 deletions app/scripts/services/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ angular.module('icestudio')
SVGO,
fastCopy,
shelljs,
sparkMD5) {
sparkMD5,
fsLock) {

let _pythonExecutableCached = null;
let _pythonPipExecutableCached = null;
Expand Down Expand Up @@ -564,7 +565,7 @@ angular.module('icestudio')
}
});
};

/*
this.saveFile = function (filepath, data) {
return new Promise(function (resolve, reject) {
var content = data;
Expand All @@ -581,6 +582,35 @@ angular.module('icestudio')
});
});
};
*/

this.saveFile = function (filepath, data) {
return new Promise(async function (resolve, reject) {
try {
// Intenta adquirir el lock en el archivo
const release = await fsLock.lock(filepath, { retries: 10 }); // Espera hasta 10 reintentos antes de fallar
var content = data;
if (typeof data !== 'string') {
content = JSON.stringify(data, null, 2);
}

// Escribe el archivo mientras mantienes el lock
nodeFs.writeFile(filepath, content, async function (err) {
if (err) {
// Libera el lock en caso de error
await release();
reject(err.toString());
} else {
// Libera el lock después de escribir exitosamente
await release();
resolve();
}
});
} catch (error) {
reject('Error while locking the file: ' + error.toString());
}
});
};

function isJSON(content) {
try {
Expand Down
59 changes: 38 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "icestudio",
"version": "0.12.1w",
"version": "0.12.2w",
"description": "Visual editor for open FPGA boards",
"contributors": [
{
Expand Down Expand Up @@ -44,8 +44,9 @@
"grunt-wget": "^0.1.3",
"grunt-zip": "^0.18.2",
"npm-platform-dependencies": "0.1.0",
"nw": "0.83.0",
"nw-builder": "^4.5.4"
"nw": "0.83.0-sdk",
"nw-builder": "^4.5.4",
"proper-lockfile": "^4.1.2"
},
"darwinDependencies": {
"fs-xattr": "^0.4.0",
Expand Down

0 comments on commit 6e929b0

Please sign in to comment.