-Stat Stat::stat(const Path &path)
-{
-#ifdef WIN32
- HANDLE handle;
- handle = CreateFile(path.str().c_str(), READ_CONTROL, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_BACKUP_SEMANTICS, 0);
- if(handle==INVALID_HANDLE_VALUE)
- {
- DWORD err = GetLastError();
- if(err==ERROR_FILE_NOT_FOUND)
- return Stat();
- else
- throw system_error("CreateFile", err);
- }
-
- BY_HANDLE_FILE_INFORMATION info;
- if(!GetFileInformationByHandle(handle, &info))
- {
- CloseHandle(handle);
- throw system_error("GetFileInformationByHandle");
- }
-
- Stat result;
- if(info.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
- result.type = DIRECTORY;
- else
- result.type = REGULAR;
-
- result.size = FileSize(info.nFileSizeHigh)<<32 | info.nFileSizeLow;
- result.alloc_size = (result.size+511)&~511;
- result.mtime = Time::TimeStamp(Time::filetime_to_rawtime(info.ftLastWriteTime));
-
- PSECURITY_DESCRIPTOR sec_desc;
- PSID owner = 0;
- PSID group = 0;
- const SECURITY_INFORMATION sec_info = OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION;
- DWORD err = GetSecurityInfo(handle, SE_FILE_OBJECT, sec_info, &owner, &group, 0, 0, &sec_desc);
- if(err)
- {
- CloseHandle(handle);
- throw system_error("GetSecurityInfo", err);
- }
-
- if(owner)
- result.owner = get_account_name(owner);
- if(group)
- result.group = get_account_name(group);
-
- LocalFree(sec_desc);
-
- CloseHandle(handle);
-
- return result;
-#else
- struct stat st;
- int ret = ::stat(path.str().c_str(), &st);
- if(ret==-1)
- {
- if(errno==ENOENT)
- return Stat();
- else
- throw system_error("stat");
- }
+Stat::Stat(const Stat &other):
+ exists(other.exists),
+ type(other.type),
+ size(other.type),
+ alloc_size(other.alloc_size),
+ mtime(other.mtime),
+ owner_info(other.owner_info),
+ priv(other.priv ? new Private(*other.priv) : 0)
+{ }