Move directory iteration helper to own file
This commit is contained in:
@@ -9,6 +9,7 @@ BinCommand package :
|
|||||||
command_list.cpp
|
command_list.cpp
|
||||||
package.cpp
|
package.cpp
|
||||||
PackageWriterListener.cpp
|
PackageWriterListener.cpp
|
||||||
|
PackageWritingUtils.cpp
|
||||||
StandardErrorOutput.cpp
|
StandardErrorOutput.cpp
|
||||||
|
|
||||||
:
|
:
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011, Ingo Weinhold, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "PackageWritingUtils.h"
|
||||||
|
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <package/hpkg/HPKGDefs.h>
|
||||||
|
|
||||||
|
#include <AutoDeleter.h>
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
add_current_directory_entries(BPackageWriter& packageWriter,
|
||||||
|
BPackageWriterListener& listener, bool skipPackageInfo)
|
||||||
|
{
|
||||||
|
// open the current directory
|
||||||
|
DIR* dir = opendir(".");
|
||||||
|
if (dir == NULL) {
|
||||||
|
listener.PrintError("Error: Failed to opendir '.': %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
CObjectDeleter<DIR, int> dirCloser(dir, &closedir);
|
||||||
|
|
||||||
|
while (dirent* entry = readdir(dir)) {
|
||||||
|
// skip "." and ".."
|
||||||
|
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// skip the .PackageInfo, if requested
|
||||||
|
if (skipPackageInfo
|
||||||
|
&& strcmp(entry->d_name, B_HPKG_PACKAGE_INFO_FILE_NAME) == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
status_t error = packageWriter.AddEntry(entry->d_name);
|
||||||
|
if (error != B_OK)
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011, Ingo Weinhold, [email protected].
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef PACKAGE_WRITING_UTILS_H
|
||||||
|
#define PACKAGE_WRITING_UTILS_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
#include <package/hpkg/PackageWriter.h>
|
||||||
|
|
||||||
|
|
||||||
|
using BPackageKit::BHPKG::BPackageWriter;
|
||||||
|
using BPackageKit::BHPKG::BPackageWriterListener;
|
||||||
|
|
||||||
|
|
||||||
|
status_t add_current_directory_entries(BPackageWriter& packageWriter,
|
||||||
|
BPackageWriterListener& listener, bool skipPackageInfo);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // PACKAGE_WRITING_UTILS_H
|
||||||
@@ -5,7 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
@@ -22,6 +21,7 @@
|
|||||||
|
|
||||||
#include "package.h"
|
#include "package.h"
|
||||||
#include "PackageWriterListener.h"
|
#include "PackageWriterListener.h"
|
||||||
|
#include "PackageWritingUtils.h"
|
||||||
#include "StandardErrorOutput.h"
|
#include "StandardErrorOutput.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -109,29 +109,9 @@ command_create(int argc, const char* const* argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add all files of current directory
|
// add all files of the current directory, save for the .PackageInfo
|
||||||
DIR* dir = opendir(".");
|
if (add_current_directory_entries(packageWriter, listener, true) != B_OK)
|
||||||
if (dir == NULL) {
|
|
||||||
listener.PrintError("Error: Failed to opendir '.': %s\n",
|
|
||||||
strerror(errno));
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
|
|
||||||
while (dirent* entry = readdir(dir)) {
|
|
||||||
// skip "." and ".."
|
|
||||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// also skip the .PackageInfo -- we'll add it later
|
|
||||||
if (strcmp(entry->d_name, B_HPKG_PACKAGE_INFO_FILE_NAME) == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
result = packageWriter.AddEntry(entry->d_name);
|
|
||||||
if (result != B_OK)
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
closedir(dir);
|
|
||||||
|
|
||||||
// add the .PackageInfo
|
// add the .PackageInfo
|
||||||
result = packageWriter.AddEntry(B_HPKG_PACKAGE_INFO_FILE_NAME,
|
result = packageWriter.AddEntry(B_HPKG_PACKAGE_INFO_FILE_NAME,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ BuildPlatformMain <build>package :
|
|||||||
command_list.cpp
|
command_list.cpp
|
||||||
package.cpp
|
package.cpp
|
||||||
PackageWriterListener.cpp
|
PackageWriterListener.cpp
|
||||||
|
PackageWritingUtils.cpp
|
||||||
StandardErrorOutput.cpp
|
StandardErrorOutput.cpp
|
||||||
|
|
||||||
:
|
:
|
||||||
|
|||||||
Reference in New Issue
Block a user