|
|
1.1 ! root 1: /* ! 2: Copyright (c) 2008 TrueCrypt Foundation. All rights reserved. ! 3: ! 4: Governed by the TrueCrypt License 2.4 the full text of which is contained ! 5: in the file License.txt included in TrueCrypt binary and source code ! 6: distribution packages. ! 7: */ ! 8: ! 9: #include "File.h" ! 10: #ifdef TC_UNIX ! 11: #include <sys/types.h> ! 12: #include <sys/stat.h> ! 13: #include <unistd.h> ! 14: #include <utime.h> ! 15: #endif ! 16: ! 17: namespace TrueCrypt ! 18: { ! 19: File::~File () ! 20: { ! 21: if (FileIsOpen) ! 22: Close(); ! 23: } ! 24: ! 25: void File::Copy (const FilePath &sourcePath, const FilePath &destinationPath, bool preserveTimestamps) ! 26: { ! 27: File source; ! 28: source.Open (sourcePath); ! 29: ! 30: File destination; ! 31: destination.Open (destinationPath, CreateWrite); ! 32: ! 33: SecureBuffer buffer (OptimalReadSize); ! 34: uint64 len; ! 35: ! 36: while ((len = source.Read (buffer)) > 0) ! 37: { ! 38: destination.Write (buffer, static_cast <size_t> (len)); ! 39: } ! 40: ! 41: if (preserveTimestamps) ! 42: { ! 43: destination.Flush(); ! 44: #ifndef TC_WINDOWS ! 45: struct stat statData; ! 46: throw_sys_sub_if (stat (string (sourcePath).c_str(), &statData) == -1, wstring (sourcePath)); ! 47: ! 48: struct utimbuf u; ! 49: u.actime = statData.st_atime; ! 50: u.modtime = statData.st_mtime; ! 51: throw_sys_sub_if (utime (string (destinationPath).c_str(), &u) == -1, wstring (destinationPath)); ! 52: #endif ! 53: } ! 54: } ! 55: ! 56: FilePath File::GetPath () const ! 57: { ! 58: if_debug (ValidateState()); ! 59: return Path; ! 60: } ! 61: ! 62: void File::ReadCompleteBuffer (const BufferPtr &buffer) const ! 63: { ! 64: size_t dataLeft = buffer.Size(); ! 65: size_t offset = 0; ! 66: ! 67: while (dataLeft > 0) ! 68: { ! 69: size_t dataRead = static_cast <size_t> (Read (buffer.GetRange (offset, dataLeft))); ! 70: if (dataRead == 0) ! 71: throw InsufficientData (SRC_POS); ! 72: ! 73: dataLeft -= dataRead; ! 74: offset += dataRead; ! 75: } ! 76: } ! 77: ! 78: void File::ValidateState () const ! 79: { ! 80: if (!FileIsOpen) ! 81: throw NotInitialized (SRC_POS); ! 82: } ! 83: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.