Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
git
提交
9614b8dc
G
git
项目概览
李少辉-开发者
/
git
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
git
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9614b8dc
编写于
4月 11, 2005
作者:
L
Linus Torvalds
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix stale index.lock file removal using "atexit()".
Problem noted by Randy Dunlap.
上级
84fe9720
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
47 addition
and
39 deletion
+47
-39
read-tree.c
read-tree.c
+23
-22
update-cache.c
update-cache.c
+24
-17
未找到文件。
read-tree.c
浏览文件 @
9614b8dc
...
...
@@ -63,6 +63,14 @@ static int read_tree(unsigned char *sha1, const char *base, int baselen)
return
0
;
}
static
int
remove_lock
=
0
;
static
void
remove_lock_file
(
void
)
{
if
(
remove_lock
)
unlink
(
".dircache/index.lock"
);
}
int
main
(
int
argc
,
char
**
argv
)
{
int
i
,
newfd
;
...
...
@@ -71,35 +79,28 @@ int main(int argc, char **argv)
newfd
=
open
(
".dircache/index.lock"
,
O_RDWR
|
O_CREAT
|
O_EXCL
,
0600
);
if
(
newfd
<
0
)
usage
(
"unable to create new cachefile"
);
atexit
(
remove_lock_file
);
remove_lock
=
1
;
for
(
i
=
1
;
i
<
argc
;
i
++
)
{
const
char
*
arg
=
argv
[
i
];
/* "-m" stands for "merge" current directory cache */
if
(
!
strcmp
(
arg
,
"-m"
))
{
if
(
active_cache
)
{
fprintf
(
stderr
,
"read-tree: cannot merge old cache on top of new
\n
"
);
goto
out
;
}
if
(
read_cache
()
<
0
)
{
fprintf
(
stderr
,
"read-tree: corrupt directory cache
\n
"
);
goto
out
;
}
if
(
active_cache
)
usage
(
"read-tree: cannot merge old cache on top of new"
);
if
(
read_cache
()
<
0
)
usage
(
"read-tree: corrupt directory cache"
);
continue
;
}
if
(
get_sha1_hex
(
arg
,
sha1
)
<
0
)
{
fprintf
(
stderr
,
"read-tree [-m] <sha1>
\n
"
);
goto
out
;
}
if
(
read_tree
(
sha1
,
""
,
0
)
<
0
)
{
fprintf
(
stderr
,
"failed to unpack tree object %s
\n
"
,
arg
);
goto
out
;
}
if
(
get_sha1_hex
(
arg
,
sha1
)
<
0
)
usage
(
"read-tree [-m] <sha1>"
);
if
(
read_tree
(
sha1
,
""
,
0
)
<
0
)
usage
(
"failed to unpack tree object %s"
,
arg
);
}
if
(
!
write_cache
(
newfd
,
active_cache
,
active_nr
)
&&
!
rename
(
".dircache/index.lock"
,
".dircache/index"
))
if
(
write_cache
(
newfd
,
active_cache
,
active_nr
)
||
rename
(
".dircache/index.lock"
,
".dircache/index"
))
usage
(
"unable to write new index file"
);
remove_lock
=
0
;
return
0
;
out:
unlink
(
".dircache/index.lock"
);
exit
(
1
);
}
update-cache.c
浏览文件 @
9614b8dc
...
...
@@ -230,22 +230,30 @@ static int verify_path(char *path)
}
}
static
int
remove_lock
=
0
;
static
void
remove_lock_file
(
void
)
{
if
(
remove_lock
)
unlink
(
".dircache/index.lock"
);
}
int
main
(
int
argc
,
char
**
argv
)
{
int
i
,
newfd
,
entries
;
int
allow_options
=
1
;
newfd
=
open
(
".dircache/index.lock"
,
O_RDWR
|
O_CREAT
|
O_EXCL
,
0600
);
if
(
newfd
<
0
)
usage
(
"unable to create new cachefile"
);
atexit
(
remove_lock_file
);
remove_lock
=
1
;
entries
=
read_cache
();
if
(
entries
<
0
)
{
perror
(
"cache corrupted"
);
return
-
1
;
}
if
(
entries
<
0
)
usage
(
"cache corrupted"
);
newfd
=
open
(
".dircache/index.lock"
,
O_RDWR
|
O_CREAT
|
O_EXCL
,
0600
);
if
(
newfd
<
0
)
{
perror
(
"unable to create new cachefile"
);
return
-
1
;
}
for
(
i
=
1
;
i
<
argc
;
i
++
)
{
char
*
path
=
argv
[
i
];
...
...
@@ -272,14 +280,13 @@ int main(int argc, char **argv)
fprintf
(
stderr
,
"Ignoring path %s
\n
"
,
argv
[
i
]);
continue
;
}
if
(
add_file_to_cache
(
path
))
{
fprintf
(
stderr
,
"Unable to add %s to database
\n
"
,
path
);
goto
out
;
if
(
add_file_to_cache
(
path
))
usage
(
"Unable to add %s to database"
,
path
);
}
}
if
(
!
write_cache
(
newfd
,
active_cache
,
active_nr
)
&&
!
rename
(
".dircache/index.lock"
,
".dircache/index"
))
return
0
;
out:
unlink
(
".dircache/index.lock"
)
;
if
(
write_cache
(
newfd
,
active_cache
,
active_nr
)
||
rename
(
".dircache/index.lock"
,
".dircache/index"
))
usage
(
"Unable to write new cachefile"
)
;
remove_lock
=
0
;
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录