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
cc2ac058
Commit
cc2ac058
authored
May 17, 2011
by
Jakob Pfender
Committed by
Vicent Marti
May 23, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fileops.c: Move to new error handling mechanism
parent
f6328611
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
16 deletions
+18
-16
src/fileops.c
+18
-16
No files found.
src/fileops.c
View file @
cc2ac058
...
@@ -36,32 +36,32 @@ int gitfo_mktemp(char *path_out, const char *filename)
...
@@ -36,32 +36,32 @@ int gitfo_mktemp(char *path_out, const char *filename)
/* FIXME: there may be race conditions when multi-threading
/* FIXME: there may be race conditions when multi-threading
* with the library */
* with the library */
if
(
_mktemp_s
(
path_out
,
GIT_PATH_MAX
)
!=
0
)
if
(
_mktemp_s
(
path_out
,
GIT_PATH_MAX
)
!=
0
)
return
GIT_EOSERR
;
return
git__throw
(
GIT_EOSERR
,
"Failed to make temporary file %s"
,
path_out
)
;
fd
=
gitfo_creat
(
path_out
,
0744
);
fd
=
gitfo_creat
(
path_out
,
0744
);
#else
#else
fd
=
mkstemp
(
path_out
);
fd
=
mkstemp
(
path_out
);
#endif
#endif
return
fd
>=
0
?
fd
:
GIT_EOSERR
;
return
fd
>=
0
?
fd
:
git__throw
(
GIT_EOSERR
,
"Failed to create temporary file %s"
,
path_out
)
;
}
}
int
gitfo_open
(
const
char
*
path
,
int
flags
)
int
gitfo_open
(
const
char
*
path
,
int
flags
)
{
{
int
fd
=
open
(
path
,
flags
|
O_BINARY
);
int
fd
=
open
(
path
,
flags
|
O_BINARY
);
return
fd
>=
0
?
fd
:
GIT_EOSERR
;
return
fd
>=
0
?
fd
:
git__throw
(
GIT_EOSERR
,
"Failed to open %s"
,
path
)
;
}
}
int
gitfo_creat
(
const
char
*
path
,
int
mode
)
int
gitfo_creat
(
const
char
*
path
,
int
mode
)
{
{
int
fd
=
open
(
path
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
|
O_BINARY
,
mode
);
int
fd
=
open
(
path
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
|
O_BINARY
,
mode
);
return
fd
>=
0
?
fd
:
GIT_EOSERR
;
return
fd
>=
0
?
fd
:
git__throw
(
GIT_EOSERR
,
"Failed to create file. Could not open %s"
,
path
)
;
}
}
int
gitfo_creat_force
(
const
char
*
path
,
int
mode
)
int
gitfo_creat_force
(
const
char
*
path
,
int
mode
)
{
{
if
(
gitfo_mkdir_2file
(
path
)
<
GIT_SUCCESS
)
if
(
gitfo_mkdir_2file
(
path
)
<
GIT_SUCCESS
)
return
GIT_EOSERR
;
return
git__throw
(
GIT_EOSERR
,
"Failed to create file %s"
,
path
)
;
return
gitfo_creat
(
path
,
mode
);
return
gitfo_creat
(
path
,
mode
);
}
}
...
@@ -74,11 +74,11 @@ int gitfo_read(git_file fd, void *buf, size_t cnt)
...
@@ -74,11 +74,11 @@ int gitfo_read(git_file fd, void *buf, size_t cnt)
if
(
r
<
0
)
{
if
(
r
<
0
)
{
if
(
errno
==
EINTR
||
errno
==
EAGAIN
)
if
(
errno
==
EINTR
||
errno
==
EAGAIN
)
continue
;
continue
;
return
GIT_EOSERR
;
return
git__throw
(
GIT_EOSERR
,
"Failed to read from file"
)
;
}
}
if
(
!
r
)
{
if
(
!
r
)
{
errno
=
EPIPE
;
errno
=
EPIPE
;
return
GIT_EOSERR
;
return
git__throw
(
GIT_EOSERR
,
"Failed to read from file"
)
;
}
}
cnt
-=
r
;
cnt
-=
r
;
b
+=
r
;
b
+=
r
;
...
@@ -94,11 +94,11 @@ int gitfo_write(git_file fd, void *buf, size_t cnt)
...
@@ -94,11 +94,11 @@ int gitfo_write(git_file fd, void *buf, size_t cnt)
if
(
r
<
0
)
{
if
(
r
<
0
)
{
if
(
errno
==
EINTR
||
errno
==
EAGAIN
)
if
(
errno
==
EINTR
||
errno
==
EAGAIN
)
continue
;
continue
;
return
GIT_EOSERR
;
return
git__throw
(
GIT_EOSERR
,
"Failed to write to file"
)
;
}
}
if
(
!
r
)
{
if
(
!
r
)
{
errno
=
EPIPE
;
errno
=
EPIPE
;
return
GIT_EOSERR
;
return
git__throw
(
GIT_EOSERR
,
"Failed to write to file"
)
;
}
}
cnt
-=
r
;
cnt
-=
r
;
b
+=
r
;
b
+=
r
;
...
@@ -112,7 +112,7 @@ int gitfo_isdir(const char *path)
...
@@ -112,7 +112,7 @@ int gitfo_isdir(const char *path)
int
len
,
stat_error
;
int
len
,
stat_error
;
if
(
!
path
)
if
(
!
path
)
return
GIT_ENOTFOUND
;
return
git__throw
(
GIT_ENOTFOUND
,
"No path given to gitfo_isdir"
)
;
len
=
strlen
(
path
);
len
=
strlen
(
path
);
...
@@ -128,10 +128,10 @@ int gitfo_isdir(const char *path)
...
@@ -128,10 +128,10 @@ int gitfo_isdir(const char *path)
}
}
if
(
stat_error
<
GIT_SUCCESS
)
if
(
stat_error
<
GIT_SUCCESS
)
return
GIT_ENOTFOUND
;
return
git__throw
(
GIT_ENOTFOUND
,
"%s does not exist"
,
path
)
;
if
(
!
S_ISDIR
(
st
.
st_mode
))
if
(
!
S_ISDIR
(
st
.
st_mode
))
return
GIT_ENOTFOUND
;
return
git__throw
(
GIT_ENOTFOUND
,
"%s is not a file"
,
path
)
;
return
GIT_SUCCESS
;
return
GIT_SUCCESS
;
}
}
...
@@ -146,7 +146,7 @@ git_off_t gitfo_size(git_file fd)
...
@@ -146,7 +146,7 @@ git_off_t gitfo_size(git_file fd)
{
{
struct
stat
sb
;
struct
stat
sb
;
if
(
gitfo_fstat
(
fd
,
&
sb
))
if
(
gitfo_fstat
(
fd
,
&
sb
))
return
GIT_EOSERR
;
return
git__throw
(
GIT_EOSERR
,
"Failed to get size of file. File missing or corrupted"
)
;
return
sb
.
st_size
;
return
sb
.
st_size
;
}
}
...
@@ -160,7 +160,7 @@ int gitfo_read_file(gitfo_buf *obj, const char *path)
...
@@ -160,7 +160,7 @@ int gitfo_read_file(gitfo_buf *obj, const char *path)
assert
(
obj
&&
path
&&
*
path
);
assert
(
obj
&&
path
&&
*
path
);
if
((
fd
=
gitfo_open
(
path
,
O_RDONLY
))
<
0
)
if
((
fd
=
gitfo_open
(
path
,
O_RDONLY
))
<
0
)
return
GIT_ERROR
;
return
git__throw
(
GIT_ERROR
,
"Failed to open %s for reading"
,
path
)
;
if
(((
size
=
gitfo_size
(
fd
))
<
0
)
||
!
git__is_sizet
(
size
+
1
))
{
if
(((
size
=
gitfo_size
(
fd
))
<
0
)
||
!
git__is_sizet
(
size
+
1
))
{
gitfo_close
(
fd
);
gitfo_close
(
fd
);
...
@@ -287,6 +287,8 @@ int gitfo_flush_cached(gitfo_cache *ioc)
...
@@ -287,6 +287,8 @@ int gitfo_flush_cached(gitfo_cache *ioc)
ioc
->
pos
=
0
;
ioc
->
pos
=
0
;
}
}
if
(
result
<
GIT_SUCCESS
)
return
git__rethrow
(
result
,
"Failed to flush cache"
);
return
result
;
return
result
;
}
}
...
@@ -325,7 +327,7 @@ int gitfo_close_cached(gitfo_cache *ioc)
...
@@ -325,7 +327,7 @@ int gitfo_close_cached(gitfo_cache *ioc)
git_file
fd
;
git_file
fd
;
if
(
gitfo_flush_cached
(
ioc
)
<
GIT_SUCCESS
)
if
(
gitfo_flush_cached
(
ioc
)
<
GIT_SUCCESS
)
return
GIT_ERROR
;
return
git__throw
(
GIT_ERROR
,
"Failed to close cache. Could not flush cache"
)
;
fd
=
ioc
->
fd
;
fd
=
ioc
->
fd
;
free
(
ioc
->
cache
);
free
(
ioc
->
cache
);
...
@@ -472,7 +474,7 @@ static int retrieve_previous_path_component_start(const char *path)
...
@@ -472,7 +474,7 @@ static int retrieve_previous_path_component_start(const char *path)
offset
--
;
offset
--
;
if
(
offset
<
root_offset
)
if
(
offset
<
root_offset
)
return
GIT_ERROR
;
return
git__throw
(
GIT_ERROR
,
"Failed to retrieve path component. Wrong offset"
)
;
while
(
offset
>
start
&&
path
[
offset
-
1
]
!=
'/'
)
{
while
(
offset
>
start
&&
path
[
offset
-
1
]
!=
'/'
)
{
offset
--
;
offset
--
;
...
...
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