Logo Search packages:      
Sourcecode: yapet version File versions  Download package

void File::write ( const BDBuffer buff,
bool  forceappend = false,
bool  forcewrite = false 
) throw (YAPETException, YAPETRetryException) [protected]

Writes at the current offset in the file.

Writes the supplied BDBuffer to disk. It writes in front of the BDBuffer its length. The length is stored in big-endian order.

Parameters:
buff reference to a BDBuffer holding the encrypted data to write
forceappend if this flag is set to true, the method first seeks to the end of the file, if set to false, it writes at the position the file pointer points to.
forcewrite before writing any data, the method checks whether the last modification date stored in mtime matches the date returned by lastModified(). If they differ, and this flag is set to false, the write operation will fail and an exception is thrown. If the flag is set to true, it writes the data to the file regardless of the last modification date.
Exceptions:
YAPETRetryException if the file has been externally modified (outside of this class), and forcewrite is not true, this exception is thrown.

Definition at line 410 of file file.cc.

References fd, filename, lastModified(), mtime, and uint32_to_disk().

Referenced by save(), setNewKey(), and writeHeader().

                                               {
    if ( (mtime != lastModified()) && !forcewrite)
      throw YAPETRetryException(_("File has been modified"));

    if (forceappend) {
      off_t pos = lseek(fd, 0, SEEK_END);
      if ( ((off_t)-1) == pos)
          throw YAPETException(strerror(errno));
    }
    uint32_t s = buff.size();

    // Convert s to the on-disk structure
    s = uint32_to_disk(s);

    int retval = ::write(fd, &s, sizeof(uint32_t));
    if (retval == -1)
      throw YAPETException(strerror(errno));
    if (retval != sizeof(uint32_t) )
      throw YAPETException(_("Short write on file: ") + filename);

    retval = ::write(fd, buff, buff.size());
    if (retval == -1)
      throw YAPETException(strerror(errno));

    if (((size_t)retval) < buff.size())
      throw YAPETException(_("Short write on file: ") + filename);

    mtime = lastModified();
}


Generated by  Doxygen 1.6.0   Back to index