Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
9abf7ea7
Commit
9abf7ea7
authored
Aug 19, 2013
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1794 from libgit2/cmn/elocked
index: report when it's locked
parents
68180808
3d276874
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
7 deletions
+37
-7
include/git2/errors.h
+1
-0
src/filebuf.c
+5
-5
src/fileops.c
+1
-1
src/index.c
+5
-1
tests-clar/index/tests.c
+25
-0
No files found.
include/git2/errors.h
View file @
9abf7ea7
...
@@ -32,6 +32,7 @@ typedef enum {
...
@@ -32,6 +32,7 @@ typedef enum {
GIT_ENONFASTFORWARD
=
-
11
,
GIT_ENONFASTFORWARD
=
-
11
,
GIT_EINVALIDSPEC
=
-
12
,
GIT_EINVALIDSPEC
=
-
12
,
GIT_EMERGECONFLICT
=
-
13
,
GIT_EMERGECONFLICT
=
-
13
,
GIT_ELOCKED
=
-
14
,
GIT_PASSTHROUGH
=
-
30
,
GIT_PASSTHROUGH
=
-
30
,
GIT_ITEROVER
=
-
31
,
GIT_ITEROVER
=
-
31
,
...
...
src/filebuf.c
View file @
9abf7ea7
...
@@ -53,7 +53,7 @@ static int lock_file(git_filebuf *file, int flags)
...
@@ -53,7 +53,7 @@ static int lock_file(git_filebuf *file, int flags)
giterr_clear
();
/* actual OS error code just confuses */
giterr_clear
();
/* actual OS error code just confuses */
giterr_set
(
GITERR_OS
,
giterr_set
(
GITERR_OS
,
"Failed to lock file '%s' for writing"
,
file
->
path_lock
);
"Failed to lock file '%s' for writing"
,
file
->
path_lock
);
return
-
1
;
return
GIT_ELOCKED
;
}
}
}
}
...
@@ -66,7 +66,7 @@ static int lock_file(git_filebuf *file, int flags)
...
@@ -66,7 +66,7 @@ static int lock_file(git_filebuf *file, int flags)
}
}
if
(
file
->
fd
<
0
)
if
(
file
->
fd
<
0
)
return
-
1
;
return
file
->
fd
;
file
->
fd_is_open
=
true
;
file
->
fd_is_open
=
true
;
...
@@ -197,7 +197,7 @@ static int write_deflate(git_filebuf *file, void *source, size_t len)
...
@@ -197,7 +197,7 @@ static int write_deflate(git_filebuf *file, void *source, size_t len)
int
git_filebuf_open
(
git_filebuf
*
file
,
const
char
*
path
,
int
flags
)
int
git_filebuf_open
(
git_filebuf
*
file
,
const
char
*
path
,
int
flags
)
{
{
int
compression
;
int
compression
,
error
=
-
1
;
size_t
path_len
;
size_t
path_len
;
/* opening an already open buffer is a programming error;
/* opening an already open buffer is a programming error;
...
@@ -282,7 +282,7 @@ int git_filebuf_open(git_filebuf *file, const char *path, int flags)
...
@@ -282,7 +282,7 @@ int git_filebuf_open(git_filebuf *file, const char *path, int flags)
memcpy
(
file
->
path_lock
+
path_len
,
GIT_FILELOCK_EXTENSION
,
GIT_FILELOCK_EXTLENGTH
);
memcpy
(
file
->
path_lock
+
path_len
,
GIT_FILELOCK_EXTENSION
,
GIT_FILELOCK_EXTLENGTH
);
/* open the file for locking */
/* open the file for locking */
if
(
lock_file
(
file
,
flags
)
<
0
)
if
(
(
error
=
lock_file
(
file
,
flags
)
)
<
0
)
goto
cleanup
;
goto
cleanup
;
}
}
...
@@ -290,7 +290,7 @@ int git_filebuf_open(git_filebuf *file, const char *path, int flags)
...
@@ -290,7 +290,7 @@ int git_filebuf_open(git_filebuf *file, const char *path, int flags)
cleanup
:
cleanup
:
git_filebuf_cleanup
(
file
);
git_filebuf_cleanup
(
file
);
return
-
1
;
return
error
;
}
}
int
git_filebuf_hash
(
git_oid
*
oid
,
git_filebuf
*
file
)
int
git_filebuf_hash
(
git_oid
*
oid
,
git_filebuf
*
file
)
...
...
src/fileops.c
View file @
9abf7ea7
...
@@ -70,7 +70,7 @@ int git_futils_creat_locked(const char *path, const mode_t mode)
...
@@ -70,7 +70,7 @@ int git_futils_creat_locked(const char *path, const mode_t mode)
if
(
fd
<
0
)
{
if
(
fd
<
0
)
{
giterr_set
(
GITERR_OS
,
"Failed to create locked file '%s'"
,
path
);
giterr_set
(
GITERR_OS
,
"Failed to create locked file '%s'"
,
path
);
return
-
1
;
return
errno
==
EEXIST
?
GIT_ELOCKED
:
-
1
;
}
}
return
fd
;
return
fd
;
...
...
src/index.c
View file @
9abf7ea7
...
@@ -498,8 +498,12 @@ int git_index_write(git_index *index)
...
@@ -498,8 +498,12 @@ int git_index_write(git_index *index)
git_vector_sort
(
&
index
->
reuc
);
git_vector_sort
(
&
index
->
reuc
);
if
((
error
=
git_filebuf_open
(
if
((
error
=
git_filebuf_open
(
&
file
,
index
->
index_file_path
,
GIT_FILEBUF_HASH_CONTENTS
))
<
0
)
&
file
,
index
->
index_file_path
,
GIT_FILEBUF_HASH_CONTENTS
))
<
0
)
{
if
(
error
==
GIT_ELOCKED
)
giterr_set
(
GITERR_INDEX
,
"The index is locked. This might be due to a concurrrent or crashed process"
);
return
error
;
return
error
;
}
if
((
error
=
write_index
(
index
,
&
file
))
<
0
)
{
if
((
error
=
write_index
(
index
,
&
file
))
<
0
)
{
git_filebuf_cleanup
(
&
file
);
git_filebuf_cleanup
(
&
file
);
...
...
tests-clar/index/tests.c
View file @
9abf7ea7
...
@@ -459,3 +459,28 @@ void test_index_tests__preserves_case(void)
...
@@ -459,3 +459,28 @@ void test_index_tests__preserves_case(void)
git_repository_free
(
repo
);
git_repository_free
(
repo
);
}
}
void
test_index_tests__elocked
(
void
)
{
git_repository
*
repo
;
git_index
*
index
;
git_filebuf
file
=
GIT_FILEBUF_INIT
;
const
git_error
*
err
;
int
error
;
cl_set_cleanup
(
&
cleanup_myrepo
,
NULL
);
cl_git_pass
(
git_repository_init
(
&
repo
,
"./myrepo"
,
0
));
cl_git_pass
(
git_repository_index
(
&
index
,
repo
));
/* Lock the index file so we fail to lock it */
cl_git_pass
(
git_filebuf_open
(
&
file
,
index
->
index_file_path
,
0
));
error
=
git_index_write
(
index
);
cl_assert_equal_i
(
GIT_ELOCKED
,
error
);
err
=
giterr_last
();
cl_assert_equal_i
(
err
->
klass
,
GITERR_INDEX
);
git_filebuf_cleanup
(
&
file
);
git_index_free
(
index
);
git_repository_free
(
repo
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment