mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-24 01:58:06 +11:00
cfspack: add the ability to spit a single file
This commit is contained in:
parent
c317fbdcf9
commit
8e2a89cea5
@ -15,6 +15,9 @@ to the filenames under it.
|
|||||||
`cfspack` takes an optional second argument, a "fnmatch" pattern. If specified,
|
`cfspack` takes an optional second argument, a "fnmatch" pattern. If specified,
|
||||||
only files patching the pattern will be included.
|
only files patching the pattern will be included.
|
||||||
|
|
||||||
|
If path is a file, a CFS with a single file will be spit and its name will
|
||||||
|
exclude the directory part of that filename.
|
||||||
|
|
||||||
The program errors out if a file name is too long (> 26 bytes) or too big
|
The program errors out if a file name is too long (> 26 bytes) or too big
|
||||||
(> 0x10000 - 0x20 bytes).
|
(> 0x10000 - 0x20 bytes).
|
||||||
|
|
||||||
|
@ -3,12 +3,20 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fnmatch.h>
|
#include <fnmatch.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#define BLKSIZE 0x100
|
#define BLKSIZE 0x100
|
||||||
#define HEADERSIZE 0x20
|
#define HEADERSIZE 0x20
|
||||||
#define MAX_FN_LEN 25 // 26 - null char
|
#define MAX_FN_LEN 25 // 26 - null char
|
||||||
#define MAX_FILE_SIZE (BLKSIZE * 0x100) - HEADERSIZE
|
#define MAX_FILE_SIZE (BLKSIZE * 0x100) - HEADERSIZE
|
||||||
|
|
||||||
|
int is_regular_file(char *path)
|
||||||
|
{
|
||||||
|
struct stat path_stat;
|
||||||
|
stat(path, &path_stat);
|
||||||
|
return S_ISREG(path_stat.st_mode);
|
||||||
|
}
|
||||||
|
|
||||||
int spitblock(char *fullpath, char *fn)
|
int spitblock(char *fullpath, char *fn)
|
||||||
{
|
{
|
||||||
FILE *fp = fopen(fullpath, "r");
|
FILE *fp = fopen(fullpath, "r");
|
||||||
@ -124,6 +132,11 @@ int main(int argc, char *argv[])
|
|||||||
if (argc == 3) {
|
if (argc == 3) {
|
||||||
pattern = argv[2];
|
pattern = argv[2];
|
||||||
}
|
}
|
||||||
return spitdir(srcpath, "", pattern);
|
if (is_regular_file(srcpath)) {
|
||||||
|
// special case: just one file
|
||||||
|
return spitblock(srcpath, basename(srcpath));
|
||||||
|
} else {
|
||||||
|
return spitdir(srcpath, "", pattern);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user