installer/CopyEngine: _CollectCopyInfo now works with all file types

CollectCopyInfo was designed to process directories only. This commit
makes it more versatile and works with everything instead.

Change-Id: Ifa74db3815411f7348e3bcc230842710058b1111
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2398
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Leorize
2020-03-22 20:40:21 +00:00
committed by Adrien Destugues
parent 18da5c3042
commit fd09d551e1
+33 -33
View File
@@ -226,56 +226,56 @@ CopyEngine::_CollectCopyInfo(const char* _source, int32& level,
{ {
level++; level++;
BDirectory source(_source); BEntry source(_source);
status_t ret = source.InitCheck(); status_t ret = source.InitCheck();
if (ret < B_OK) if (ret < B_OK)
return ret; return ret;
BEntry entry; struct stat statInfo;
while (source.GetNextEntry(&entry) == B_OK) { ret = source.GetStat(&statInfo);
SemaphoreLocker lock(cancelSemaphore); if (ret < B_OK)
if (cancelSemaphore >= 0 && !lock.IsLocked()) { return ret;
// We are supposed to quit
return B_CANCELED;
}
struct stat statInfo; SemaphoreLocker lock(cancelSemaphore);
entry.GetStat(&statInfo); if (cancelSemaphore >= 0 && !lock.IsLocked()) {
// We are supposed to quit
return B_CANCELED;
}
BPath sourceEntryPath; if (fEntryFilter != NULL
status_t ret = entry.GetPath(&sourceEntryPath); && !fEntryFilter->ShouldCopyEntry(source,
_RelativeEntryPath(_source), statInfo, level)) {
// Skip this entry
return B_OK;
}
if (cancelSemaphore >= 0)
lock.Unlock();
if (S_ISDIR(statInfo.st_mode)) {
BDirectory srcFolder(&source);
ret = srcFolder.InitCheck();
if (ret < B_OK) if (ret < B_OK)
return ret; return ret;
if (fEntryFilter != NULL BEntry entry;
&& !fEntryFilter->ShouldCopyEntry(entry, while (srcFolder.GetNextEntry(&entry) == B_OK) {
_RelativeEntryPath(sourceEntryPath.Path()), statInfo, level)) { BPath entryPath;
continue; ret = entry.GetPath(&entryPath);
}
if (S_ISDIR(statInfo.st_mode)) {
// handle recursive directory copy
BPath srcFolder;
ret = entry.GetPath(&srcFolder);
if (ret < B_OK) if (ret < B_OK)
return ret; return ret;
if (cancelSemaphore >= 0) ret = _CollectCopyInfo(entryPath.Path(), level, cancelSemaphore);
lock.Unlock();
ret = _CollectCopyInfo(srcFolder.Path(), level, cancelSemaphore);
if (ret < B_OK) if (ret < B_OK)
return ret; return ret;
} else if (S_ISLNK(statInfo.st_mode)) {
// link, ignore size
} else {
// file data
fBytesToCopy += statInfo.st_size;
} }
} else if (S_ISLNK(statInfo.st_mode)) {
fItemsToCopy++; // link, ignore size
} else {
fBytesToCopy += statInfo.st_size;
} }
fItemsToCopy++;
level--; level--;
return B_OK; return B_OK;
} }