Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nccf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
702
Provoz
nccf
Commits
968471f6
Commit
968471f6
authored
12 years ago
by
Yorhel
Browse files
Options
Downloads
Patches
Plain Diff
Omit "dev" field in export when same as parent dir + "excluded" fix
parent
c4616ff1
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/dir_export.c
+22
-9
22 additions, 9 deletions
src/dir_export.c
src/util.h
+21
-0
21 additions, 0 deletions
src/util.h
with
43 additions
and
9 deletions
src/dir_export.c
+
22
−
9
View file @
968471f6
...
...
@@ -31,7 +31,12 @@
static
FILE
*
stream
;
static
int
level
;
/* Current level of nesting */
/* Stack of device IDs, also used to determine the */
struct
stack
{
uint64_t
*
list
;
int
size
,
top
;
}
stack
;
static
void
output_string
(
const
char
*
str
)
{
...
...
@@ -81,9 +86,10 @@ static void output_info(struct dir *d) {
fputs
(
",
\"
dsize
\"
:"
,
stream
);
output_int
((
uint64_t
)
d
->
size
);
}
/* TODO: No need to include a dev is it's the same as the parent dir. */
fputs
(
",
\"
dev
\"
:"
,
stream
);
output_int
(
d
->
dev
);
if
(
d
->
dev
!=
nstack_top
(
&
stack
,
0
))
{
fputs
(
",
\"
dev
\"
:"
,
stream
);
output_int
(
d
->
dev
);
}
fputs
(
",
\"
ino
\"
:"
,
stream
);
output_int
(
d
->
ino
);
if
(
d
->
flags
&
FF_HLNKC
)
/* TODO: Including the actual number of links would be nicer. */
...
...
@@ -93,9 +99,9 @@ static void output_info(struct dir *d) {
if
(
!
(
d
->
flags
&
(
FF_DIR
|
FF_FILE
)))
fputs
(
",
\"
notreg
\"
:true"
,
stream
);
if
(
d
->
flags
&
FF_EXL
)
fputs
(
",
\"
excluded
\"
:
\"
pattern"
,
stream
);
fputs
(
",
\"
excluded
\"
:
\"
pattern
\"
"
,
stream
);
else
if
(
d
->
flags
&
FF_OTHFS
)
fputs
(
",
\"
excluded
\"
:
\"
othfs"
,
stream
);
fputs
(
",
\"
excluded
\"
:
\"
othfs
\"
"
,
stream
);
fputc
(
'}'
,
stream
);
}
...
...
@@ -107,7 +113,8 @@ static void output_info(struct dir *d) {
* called with a stream that's in an error state. */
static
int
item
(
struct
dir
*
item
)
{
if
(
!
item
)
{
if
(
!--
level
)
{
/* closing of the root item */
nstack_pop
(
&
stack
);
if
(
!
stack
.
top
)
{
/* closing of the root item */
fputs
(
"]]"
,
stream
);
return
fclose
(
stream
);
}
else
/* closing of a regular directory item */
...
...
@@ -119,7 +126,7 @@ static int item(struct dir *item) {
/* File header.
* TODO: Add scan options? */
if
(
item
->
flags
&
FF_DIR
&&
!
level
++
)
if
(
!
stack
.
top
)
fputs
(
"[1,0,{
\"
progname
\"
:
\"
"
PACKAGE
"
\"
,
\"
progver
\"
:
\"
"
PACKAGE_VERSION
"
\"
}"
,
stream
);
fputs
(
",
\n
"
,
stream
);
...
...
@@ -127,11 +134,16 @@ static int item(struct dir *item) {
fputc
(
'['
,
stream
);
output_info
(
item
);
if
(
item
->
flags
&
FF_DIR
)
nstack_push
(
&
stack
,
item
->
dev
);
return
ferror
(
stream
);
}
static
int
final
(
int
fail
)
{
nstack_free
(
&
stack
);
return
fail
?
1
:
1
;
/* Silences -Wunused-parameter */
}
...
...
@@ -142,7 +154,8 @@ int dir_export_init(const char *fn) {
else
if
((
stream
=
fopen
(
fn
,
"w"
))
==
NULL
)
return
1
;
level
=
0
;
nstack_init
(
&
stack
);
pstate
=
ST_CALC
;
dir_output
.
item
=
item
;
dir_output
.
final
=
final
;
...
...
This diff is collapsed.
Click to expand it.
src/util.h
+
21
−
0
View file @
968471f6
...
...
@@ -84,5 +84,26 @@ struct dir *getroot(struct dir *);
/* Adds a value to the size, asize and items fields of *d and its parents */
void
addparentstats
(
struct
dir
*
,
int64_t
,
int64_t
,
int
);
/* A simple stack implemented in macros */
#define nstack_init(_s) do {\
(_s)->size = 10;\
(_s)->top = 0;\
(_s)->list = malloc(10*sizeof(*(_s)->list));\
} while(0)
#define nstack_push(_s, _v) do {\
if((_s)->size <= (_s)->top) {\
(_s)->size *= 2;\
(_s)->list = realloc((_s)->list, (_s)->size*sizeof(*(_s)->list));\
}\
(_s)->list[(_s)->top++] = _v;\
} while(0)
#define nstack_pop(_s) (_s)->top--
#define nstack_top(_s, _d) ((_s)->top > 0 ? (_s)->list[(_s)->top-1] : (_d))
#define nstack_free(_s) free((_s)->list)
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment