Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/ls4mkbom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@
using namespace std;

void usage() {
cout << "Usage: ls4mkbom [-u uid] [-g gid] path" << endl << endl;
cout << "Usage: ls4mkbom [-u uid] [-g gid] [-H] path" << endl << endl;
cout << "\t-u\tForce user ID to the specified value" << endl;
cout << "\t-g\tForce group ID to the specified value" << endl;
cout << "\t-H\tInclude hidden files" << endl;
}

int main( int argc, char * argv[] ) {
uint32_t uid = UINT_MAX;
uint32_t gid = UINT_MAX;
bool includeHidden = false;

while (true) {
signed char c = getopt(argc, argv, "hu:g:");
signed char c = getopt(argc, argv, "hu:g:H");
if (c == -1) {
break;
}
Expand All @@ -52,6 +54,9 @@ int main( int argc, char * argv[] ) {
case 'g':
gid = atol(optarg);
break;
case 'H':
includeHidden = true;
break;
case 'h':
usage();
return 0;
Expand All @@ -67,6 +72,6 @@ int main( int argc, char * argv[] ) {
return 1;
}

print_node( cout, argv[optind], uid, gid );
print_node( cout, argv[optind], uid, gid, includeHidden );
return 0;
}
11 changes: 8 additions & 3 deletions src/mkbom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,19 +473,21 @@ void write_bom( istream & lsbom_file, const string & output_path ) {
}

void usage() {
cout << "Usage: mkbom [i] [-u uid] [-g gid] source target-bom-file" << endl << endl;
cout << "Usage: mkbom [i] [-u uid] [-g gid] [-H] source target-bom-file" << endl << endl;
cout << "\t-i\tTreat source as a file in the format generated by ls4mkbom and lsbom" << endl;
cout << "\t-u\tForce user ID to the specified value (incompatible with -i)" << endl;
cout << "\t-g\tForce group ID to the specified value (incompatible with -i)" << endl;
cout << "\t-H\tInclude hidden files" << endl;
}

int main( int argc, char * argv[] ) {
uint32_t uid = UINT_MAX;
uint32_t gid = UINT_MAX;
bool isFileListSource = false;
bool includeHidden = false;

while (true) {
signed char c = getopt(argc, argv, "hiu:g:");
signed char c = getopt(argc, argv, "hiu:g:H");
if (c == -1) {
break;
}
Expand All @@ -500,6 +502,9 @@ int main( int argc, char * argv[] ) {
case 'g':
gid = atol(optarg);
break;
case 'H':
includeHidden = true;
break;
case 'h':
usage();
return 0;
Expand Down Expand Up @@ -530,7 +535,7 @@ int main( int argc, char * argv[] ) {
string buffer;
{
stringstream ss;
print_node( ss, string( argv[optind] ), uid, gid );
print_node( ss, string( argv[optind] ), uid, gid, includeHidden );
buffer = ss.str();
}
stringstream file_list( buffer );
Expand Down
19 changes: 12 additions & 7 deletions src/printnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ using namespace std;

/* on unix system_path = path; on windows system_path is the windows native path format of path */
void print_node( ostream & output, const string & base, const string & system_path, const string & path,
uint32_t uid, uint32_t gid) {
uint32_t uid, uint32_t gid, bool includeHidden) {
struct stat s;
string fullpath( base );
#if defined(WINDOWS)
Expand Down Expand Up @@ -78,23 +78,28 @@ void print_node( ostream & output, const string & base, const string & system_pa
DIR * d = opendir( fullpath.c_str() );
struct dirent * dir;
while ( ( dir = readdir( d ) ) != NULL ) {
if ( dir->d_name[0] != '.' ) {
string name = string( dir->d_name );
if ( !includeHidden
? dir->d_name[0] != '.'
: (name.compare(".") != 0 && name.compare("..") != 0)
) {

string new_path(path);
new_path += string( "/" ) + string( dir->d_name );
new_path += string( "/" ) + name;
#if defined(WINDOWS)
string new_system_path(system_path);
new_system_path += string( "\\" ) + string( dir->d_name );
new_system_path += string( "\\" ) + name;
#else
string new_system_path( new_path );
#endif
print_node( output, base, new_system_path, new_path, uid, gid );
print_node( output, base, new_system_path, new_path, uid, gid, includeHidden );
}
}
closedir( d );
}
}

void print_node( ostream & output, string directory, uint32_t uid, uint32_t gid ) {
void print_node( ostream & output, string directory, uint32_t uid, uint32_t gid, bool includeHidden ) {
if ( directory.size() < 1 ) {
cerr << "Invalid path" << endl;
exit(1);
Expand All @@ -111,5 +116,5 @@ void print_node( ostream & output, string directory, uint32_t uid, uint32_t gid
cout << endl << "Argument must be a directory" << endl;
exit(1);
}
print_node( output, directory, "", ".", uid, gid );
print_node( output, directory, "", ".", uid, gid, includeHidden );
}
2 changes: 1 addition & 1 deletion src/printnode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
#include <climits>
#include <stdint.h>

void print_node( std::ostream & output, std::string directory, uint32_t uid, uint32_t gid );
void print_node( std::ostream & output, std::string directory, uint32_t uid, uint32_t gid, bool includeHidden );