#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
+#include <userfunc.hpp>
+
#include <sys/stat.h>
namespace I2n
bool set_file_mode(mode_t mode);
+ bool set_owner(const I2n::User& user, const I2n::Group& group= I2n::Group());
+
bool unlink();
bool is_unlinked()
std::string originalfilename;
bool full_sync;
mode_t filemode_on_close;
+ I2n::User UserOnClose;
+ I2n::Group GroupOnClose;
public:
static const std::string default_template_suffix;
tmpfcopystreamTempl()
: full_sync(default_full_sync),
filemode_on_close(default_filemode_on_close),
+ UserOnClose(), GroupOnClose(),
tmpfstreamTempl<Device, Tr, Alloc>()
{ }
int buffer_size = -1 , int pback_size = -1)
: full_sync(default_full_sync),
filemode_on_close(default_filemode_on_close),
+ UserOnClose(), GroupOnClose(),
originalfilename(filename),
tmpfstreamTempl<Device, Tr, Alloc>
(filename+default_template_suffix,mode,buffer_size,pback_size)
int buffer_size = -1 , int pback_size = -1)
: full_sync(default_full_sync),
filemode_on_close(default_filemode_on_close),
+ UserOnClose(), GroupOnClose(),
originalfilename(filename),
tmpfstreamTempl<Device, Tr, Alloc>
(tmpnametemplate,mode,buffer_size,pback_size)
{ return filemode_on_close; }
/**
+ * @brief Change file owner (chown) that will be set on @ref close
+ * @param user the new owner
+ * @param group the new group, if left empty the main group of the user is set
+ */
+ void set_owner_on_close(const I2n::User& user, const I2n::Group& group= I2n::Group())
+ {
+ UserOnClose=user;
+ GroupOnClose=group;
+ }
+
+ /**
+ * @brief Get file owner that will be set on @ref close
+ * @retval user that will be set on @ref close, an empty @ref User() means nothing will be set
+ */
+ I2n::User get_owner_on_close()
+ { return UserOnClose; }
+
+ /**
+ * @brief Get file owner group that will be set on @ref close
+ * @retval group that will be set on @ref close
+ */
+ I2n::Group get_group_on_close()
+ { return GroupOnClose; }
+
+ /**
* @brief Delete the file.
*
* calling unlink is a safe way to abort,
* @brief Changes permissions (chmod) of the file.
*
* @param mode the new mode as in chmod
+* @retval true if successful
*/
template< typename Device, typename Tr, typename Alloc >
bool tmpfstreamTempl<Device,Tr,Alloc>::set_file_mode(mode_t mode)
}
/**
+* @brief Changes the owner of the file (chown).
+*
+* @param user the new owner
+* @param group the new group, if left empty the main group of the user is set
+* @retval true if successful
+*/
+template< typename Device, typename Tr, typename Alloc >
+bool tmpfstreamTempl<Device,Tr,Alloc>::set_owner(const I2n::User& user, const I2n::Group& group)
+{
+ if (!get_tmp_filename().empty() && !is_unlinked())
+ return I2n::chown(get_tmp_filename(),user,group);
+ else
+ return false;
+}
+
+/**
* @brief Delete the file.
*
* Can be called while the file is still open.
tmpfstreamTempl<Device,Tr,Alloc>::set_file_mode(filemode_on_close);
+ if (UserOnClose != I2n::User())
+ tmpfstreamTempl<Device,Tr,Alloc>::set_owner(UserOnClose,GroupOnClose);
+
move(get_original_filename(),true);
if (get_full_sync())