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
18
19status_t
20add_current_directory_entries(BPackageWriter& packageWriter,
21	BPackageWriterListener& listener, bool skipPackageInfo)
22{
23	// open the current directory
24	DIR* dir = opendir(".");
25	if (dir == NULL) {
26		listener.PrintError("Error: Failed to opendir '.': %s\n",
27			strerror(errno));
28		return errno;
29	}
30	CObjectDeleter<DIR, int> dirCloser(dir, &closedir);
31
32	while (dirent* entry = readdir(dir)) {
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, B_HPKG_PACKAGE_INFO_FILE_NAME) == 0) {
40			continue;
41		}
42
43		status_t error = packageWriter.AddEntry(entry->d_name);
44		if (error != B_OK)
45			return error;
46	}
47
48	return B_OK;
49}
50