Skip to content

Commit 0454485

Browse files
committed
Merge pull request nodegit#425 from nodegit/fix-file-lock
Attempt to fix Windows file locking bug
2 parents d439162 + 342b6e6 commit 0454485

File tree

23 files changed

+119
-69
lines changed

23 files changed

+119
-69
lines changed

generate/input/descriptor.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,9 +1431,6 @@
14311431
"git_repository_fetchhead_foreach": {
14321432
"ignore": true
14331433
},
1434-
"git_repository_free": {
1435-
"ignore": true
1436-
},
14371434
"git_repository_hashfile": {
14381435
"ignore": true
14391436
},

generate/scripts/generateNativeCode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ module.exports = function generateNativeCode() {
144144
});
145145
}
146146
})
147-
});
147+
}).catch(console.log);
148148

149149
};
150150

generate/scripts/helpers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ var Helpers = {
288288
// available
289289
if (key == typeDef.cType + "_free") {
290290
typeDef.freeFunctionName = key;
291-
fnDef.ignore = true;
292-
return;
291+
//fnDef.ignore = true;
292+
//return;
293293
}
294294

295295
fnDef.cppFunctionName = Helpers.cTypeToCppName(key, "git_" + typeDef.typeName);

generate/templates/partials/sync_function.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) {
3030

3131
{%each args|argsInfo as arg %}
3232
{%endeach%}
33+
34+
{%-- Inside a free call, if the value is already free'd don't do it again.--%}
35+
{% if cppFunctionName == "Free" %}
36+
if (ObjectWrap::Unwrap<{{ cppClassName }}>(args.This())->GetValue() != NULL) {
37+
{% endif %}
38+
3339
{%if .|hasReturns %}
3440
{{ return.cType }} result = {%endif%}{{ cFunctionName }}(
3541
{%each args|argsInfo as arg %}
@@ -67,6 +73,12 @@ from_{{ arg.name }}
6773
}
6874
{%endif%}
6975

76+
{% if cppFunctionName == "Free" %}
77+
ObjectWrap::Unwrap<{{ cppClassName }}>(args.This())->ClearValue();
78+
}
79+
{% endif %}
80+
81+
7082
{%each args|argsInfo as arg %}
7183
{%if arg | isOid %}
7284
if (args[{{ arg.jsArg }}]->IsString()) {

generate/templates/templates/class_content.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ using namespace node;
3535
{% if freeFunctionName %}
3636
if (this->selfFreeing) {
3737
{{ freeFunctionName }}(this->raw);
38+
this->raw = NULL;
3839
}
3940
{% endif %}
4041

@@ -112,7 +113,11 @@ using namespace node;
112113
}
113114

114115
{{ cType }} **{{ cppClassName }}::GetRefValue() {
115-
return &this->raw;
116+
return this->raw == NULL ? NULL : &this->raw;
117+
}
118+
119+
void {{ cppClassName }}::ClearValue() {
120+
this->raw = NULL;
116121
}
117122

118123
{% else %}

generate/templates/templates/class_header.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class {{ cppClassName }} : public ObjectWrap {
3838
{%if cType%}
3939
{{ cType }} *GetValue();
4040
{{ cType }} **GetRefValue();
41+
void ClearValue();
4142

4243
static Handle<v8::Value> New(void *raw, bool selfFreeing);
4344
{%endif%}

generate/templates/templates/struct_content.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ Handle<v8::Value> {{ cppClassName }}::New(void* raw, bool selfFreeing) {
138138
}
139139

140140
{{ cType }} **{{ cppClassName }}::GetRefValue() {
141-
return &this->raw;
141+
return this->raw == NULL ? NULL : &this->raw;
142+
}
143+
144+
void {{ cppClassName }}::ClearValue() {
145+
this->raw = NULL;
142146
}
143147

144148
{% partial fieldAccessors . %}

generate/templates/templates/struct_header.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class {{ cppClassName }} : public ObjectWrap {
2626

2727
{{ cType }} *GetValue();
2828
{{ cType }} **GetRefValue();
29+
void ClearValue();
2930

3031
static Handle<v8::Value> New(void *raw, bool selfFreeing);
3132

test/runner.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,18 @@ beforeEach(function() {
4545
return exec("git reset --hard", {cwd: workdirPath});
4646
});
4747
});
48+
49+
afterEach(function(done) {
50+
// In Windows if you do not clean up the repository, there may become a
51+
// conflict with file locking.
52+
if (this.repository && process.platform === "win32") {
53+
this.repository.stateCleanup();
54+
this.repository.free();
55+
delete this.repository;
56+
}
57+
58+
process.nextTick(function() {
59+
global.gc();
60+
done();
61+
});
62+
});

test/tests/attr.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe("Attr", function() {
99

1010
var reposPath = local("../repos/workdir/.git");
1111

12-
before(function() {
12+
beforeEach(function() {
1313
var test = this;
1414

1515
return Repository.open(reposPath)

0 commit comments

Comments
 (0)