public:
tmpfstreamTempl()
- : bio::stream<Device, Tr, Alloc>()
+ : unlinked(false), bio::stream<Device, Tr, Alloc>()
{ }
tmpfstreamTempl(const std::string& tmpnametemplate,
std::ios_base::open_mode mode = std::ios_base::out,
int buffer_size = -1 , int pback_size = -1)
- : bio::stream<Device, Tr, Alloc>()
+ : unlinked(false), bio::stream<Device, Tr, Alloc>()
{
open(tmpnametemplate,mode,buffer_size,pback_size);
}
private:
std::string originalfilename;
bool full_sync;
+ int filemode_on_close;
public:
static const std::string default_template_suffix;
+ static const bool default_full_sync=false;
+ static const int default_filemode_on_close=0644;
tmpfcopystreamTempl()
- : tmpfstreamTempl<Device, Tr, Alloc>()
+ : full_sync(default_full_sync),
+ filemode_on_close(default_filemode_on_close),
+ tmpfstreamTempl<Device, Tr, Alloc>()
{ }
tmpfcopystreamTempl(const std::string& filename,
std::ios_base::open_mode mode = std::ios_base::out,
int buffer_size = -1 , int pback_size = -1)
- : originalfilename(filename),
+ : full_sync(default_full_sync),
+ filemode_on_close(default_filemode_on_close),
+ originalfilename(filename),
tmpfstreamTempl<Device, Tr, Alloc>
(filename+default_template_suffix,mode,buffer_size,pback_size)
{ }
const std::string& tmpnametemplate,
std::ios_base::open_mode mode = std::ios_base::out,
int buffer_size = -1 , int pback_size = -1)
- : originalfilename(filename),
+ : full_sync(default_full_sync),
+ filemode_on_close(default_filemode_on_close),
+ originalfilename(filename),
tmpfstreamTempl<Device, Tr, Alloc>
(tmpnametemplate,mode,buffer_size,pback_size)
{ }
::open(tmpnametemplate,mode,buffer_size,pback_size);
}
+ void close();
+
std::string get_original_filename()
{ return originalfilename; }
bool get_full_sync()
{ return full_sync; }
- void close();
+ void set_filemode_on_close(int mode)
+ { filemode_on_close=mode; }
- // TODO: filemode on close
+ int get_filemode_on_close()
+ { return filemode_on_close; }
- // calling unlink is a safe way to abort, the original file is not overwritten then
+ // calling unlink is a safe way to abort,
+ // the original file is not overwritten then
private:
template< typename Device, typename Tr, typename Alloc >
void tmpfcopystreamTempl<Device,Tr,Alloc>::close()
{
- if (!tmpfcopystreamTempl<Device,Tr,Alloc>::is_open() ||
- tmpfcopystreamTempl<Device,Tr,Alloc>::is_unlinked())
+ if (!tmpfstreamTempl<Device,Tr,Alloc>::is_open() ||
+ tmpfstreamTempl<Device,Tr,Alloc>::is_unlinked())
return;
// TODO full sync
- // TODO chmod
-
// close the underlying filedescriptor
tmpfstreamTempl<Device,Tr,Alloc>::close();
+ tmpfstreamTempl<Device,Tr,Alloc>::set_file_mode(filemode_on_close);
+
move(get_original_filename(),true);
}
BOOST_CHECK_EQUAL( "blah", read_file(".foobar") );
tmpf.close();
+ BOOST_CHECK_EQUAL( false, tmpf.is_open() );
BOOST_CHECK_EQUAL( "hello world", read_file(".foobar") );
unlink(".foobar");
}
+BOOST_AUTO_TEST_CASE(TmpfcopystreamChmod)
+{
+ write_file(".foobar","blah");
+ chmod(".foobar",0644);
+ Stat stat_orig(".foobar");
+ BOOST_CHECK_EQUAL( 0644, stat_orig.mode() );
+
+ tmpfcopystream tmpf(".foobar");
+
+ tmpf << "hello world";
+ tmpf.flush();
+
+ tmpf.set_filemode_on_close(0640);
+
+ Stat stat_tmp(tmpf.get_tmp_filename());
+ BOOST_CHECK_EQUAL( 0600, stat_tmp.mode() );
+
+ tmpf.close();
+
+ stat_orig.recheck();
+ BOOST_CHECK_EQUAL( 0640, stat_orig.mode() );
+
+ unlink(".foobar");
+}
+
+
BOOST_AUTO_TEST_SUITE_END()