1/*
2 * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include "PackageWritingUtils.h"
8
9#include <dirent.h>
10#include <errno.h>
11#include <stdio.h>
12#include <string.h>
13
14#include <package/hpkg/HPKGDefs.h>
15
16#include <AutoDeleter.h>
17#include <AutoDeleterPosix.h>
18
19
20status_t
21add_current_directory_entries(BPackageWriter& packageWriter,
22	BPackageWriterListener& listener, bool skipPackageInfo)
23{
24	// open the current directory
25	DirCloser dir(opendir("."));
26	if (!dir.IsSet()) {
27		listener.PrintError("Error: Failed to opendir '.': %s\n",
28			strerror(errno));
29		return errno;
30	}
31
32	while (dirent* entry = readdir(dir.Get())) {
33		// skip "." and ".."
34		if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
35			continue;
36
37		// skip the .PackageInfo, if requested
38		if (skipPackageInfo
39			&& strcmp(entry->d_name,
40				BPackageKit::BHPKG::B_HPKG_PACKAGE_INFO_FILE_NAME) == 0) {
41			continue;
42		}
43
44		status_t error = packageWriter.AddEntry(entry->d_name);
45		if (error != B_OK)
46			return error;
47	}
48
49	return B_OK;
50}
51