mirror of
https://github.com/amadvance/snapraid.git
synced 2026-12-01 04:17:02 -05:00
Merges handle_close_if_different() with handle_close().
This commit is contained in:
parent
399f181a57
commit
e6b02b7d2d
1 changed files with 12 additions and 30 deletions
42
handle.c
42
handle.c
|
|
@ -24,36 +24,6 @@
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
/* handle */
|
/* handle */
|
||||||
|
|
||||||
int handle_close_if_different(struct snapraid_handle* handle, struct snapraid_file* file)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* if it's the same file, nothing to do */
|
|
||||||
if (handle->file == file) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* reset the file */
|
|
||||||
handle->file = 0;
|
|
||||||
|
|
||||||
/* close if already open */
|
|
||||||
if (handle->f != -1) {
|
|
||||||
ret = close(handle->f);
|
|
||||||
if (ret != 0) {
|
|
||||||
/* invalidate for error */
|
|
||||||
handle->f = -1;
|
|
||||||
|
|
||||||
fprintf(stderr, "Error closing file '%s'. %s.\n", handle->file->sub, strerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* reset the descriptor */
|
|
||||||
handle->f = -1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int handle_ancestor(const char* file)
|
int handle_ancestor(const char* file)
|
||||||
{
|
{
|
||||||
char dir[PATH_MAX];
|
char dir[PATH_MAX];
|
||||||
|
|
@ -236,6 +206,7 @@ int handle_close(struct snapraid_handle* handle)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
/* close if open */
|
||||||
if (handle->f != -1) {
|
if (handle->f != -1) {
|
||||||
ret = close(handle->f);
|
ret = close(handle->f);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
|
|
@ -248,12 +219,23 @@ int handle_close(struct snapraid_handle* handle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* reset the descriptor */
|
||||||
handle->file = 0;
|
handle->file = 0;
|
||||||
handle->f = -1;
|
handle->f = -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int handle_close_if_different(struct snapraid_handle* handle, struct snapraid_file* file)
|
||||||
|
{
|
||||||
|
/* if it's the same file, nothing to do */
|
||||||
|
if (handle->file == file) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return handle_close(handle);
|
||||||
|
}
|
||||||
|
|
||||||
int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, unsigned char* block_buffer, unsigned block_size)
|
int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, unsigned char* block_buffer, unsigned block_size)
|
||||||
{
|
{
|
||||||
ssize_t read_ret;
|
ssize_t read_ret;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue