close file after getting ioc flags. closes #48

This commit is contained in:
Antonio SJ Musumeci 2015-02-17 00:28:27 -05:00
parent f3f5a18ef5
commit 1a1c9db37b

View File

@ -376,37 +376,23 @@ namespace fs
return setxattrs(to,attrs);
}
static
int
copyattr(const string &from,
const string &to)
get_fs_ioc_flags(const string &file,
int &flags)
{
int fd;
int rv;
int flags;
int error;
const int openflags = O_RDONLY|O_NONBLOCK;
fd = ::open(from.c_str(),openflags);
fd = ::open(file.c_str(),openflags);
if(fd == -1)
return -1;
rv = ::ioctl(fd,FS_IOC_GETFLAGS,&flags);
if(rv == -1)
{
error = errno;
::close(fd);
errno = error;
return -1;
}
fd = ::open(to.c_str(),openflags);
if(fd == -1)
return -1;
rv = ::ioctl(fd,FS_IOC_SETFLAGS,&flags);
if(rv == -1)
{
error = errno;
int error = errno;
::close(fd);
errno = error;
return -1;
@ -415,6 +401,45 @@ namespace fs
return ::close(fd);
}
static
int
set_fs_ioc_flags(const string &file,
const int flags)
{
int fd;
int rv;
const int openflags = O_RDONLY|O_NONBLOCK;
fd = ::open(file.c_str(),openflags);
if(fd == -1)
return -1;
rv = ::ioctl(fd,FS_IOC_SETFLAGS,&flags);
if(rv == -1)
{
int error = errno;
::close(fd);
errno = error;
return -1;
}
return ::close(fd);
}
int
copyattr(const string &from,
const string &to)
{
int rv;
int flags;
rv = get_fs_ioc_flags(from,flags);
if(rv == -1)
return -1;
return set_fs_ioc_flags(to,flags);
}
int
clonepath(const string &fromsrc,
const string &tosrc,