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
c4616ff1
Commit
c4616ff1
authored
12 years ago
by
Yorhel
Browse files
Options
Downloads
Patches
Plain Diff
Added simple error checking & handling when exporting
parent
7ccb9800
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/dir.h
+4
-1
4 additions, 1 deletion
src/dir.h
src/dir_export.c
+9
-4
9 additions, 4 deletions
src/dir_export.c
src/dir_mem.c
+4
-2
4 additions, 2 deletions
src/dir_mem.c
src/dir_scan.c
+34
-13
34 additions, 13 deletions
src/dir_scan.c
with
51 additions
and
20 deletions
src/dir.h
+
4
−
1
View file @
c4616ff1
...
...
@@ -64,8 +64,11 @@ struct dir_output {
* All other fields/flags should be initialzed to NULL or 0.
* *item may be overwritten or freed in subsequent calls, so this function
* should make a copy if necessary.
*
* The function should return non-zero on error, at which point errno is
* assumed to be set to something sensible.
*/
void
(
*
item
)(
struct
dir
*
);
int
(
*
item
)(
struct
dir
*
);
/* Finalizes the output to go to the next program state or exit ncdu. Called
* after item(NULL) has been called for the root item or before any item()
...
...
This diff is collapsed.
Click to expand it.
src/dir_export.c
+
9
−
4
View file @
c4616ff1
...
...
@@ -100,15 +100,19 @@ static void output_info(struct dir *d) {
}
/* TODO: Error handling / reporting! */
static
void
item
(
struct
dir
*
item
)
{
/* Note on error handling: For convenience, we just keep writing to *stream
* without checking the return values of the functions. Only at the and of each
* item() call do we check for ferror(). This greatly simplifies the code, but
* assumes that calls to fwrite()/fput./etc don't do any weird stuff when
* 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 */
fputs
(
"]]"
,
stream
);
fclose
(
stream
);
return
fclose
(
stream
);
}
else
/* closing of a regular directory item */
fputs
(
"]"
,
stream
);
return
;
return
ferror
(
stream
)
;
}
dir_output
.
items
++
;
...
...
@@ -123,6 +127,7 @@ static void item(struct dir *item) {
fputc
(
'['
,
stream
);
output_info
(
item
);
return
ferror
(
stream
);
}
...
...
This diff is collapsed.
Click to expand it.
src/dir_mem.c
+
4
−
2
View file @
c4616ff1
...
...
@@ -128,13 +128,13 @@ static void item_add(struct dir *item) {
}
static
void
item
(
struct
dir
*
item
)
{
static
int
item
(
struct
dir
*
item
)
{
struct
dir
*
t
;
/* Go back to parent dir */
if
(
!
item
)
{
curdir
=
curdir
->
parent
;
return
;
return
0
;
}
item
=
item_copy
(
item
);
...
...
@@ -165,6 +165,8 @@ static void item(struct dir *item) {
dir_output
.
size
=
root
->
size
;
dir_output
.
items
=
root
->
items
;
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
src/dir_scan.c
+
34
−
13
View file @
c4616ff1
...
...
@@ -125,16 +125,20 @@ static int dir_scan_recurse(struct dir *d) {
if
(
chdir
(
d
->
name
))
{
dir_setlasterr
(
dir_curpath
);
d
->
flags
|=
FF_ERR
;
dir_output
.
item
(
d
);
dir_output
.
item
(
NULL
);
if
(
dir_output
.
item
(
d
)
||
dir_output
.
item
(
NULL
))
{
dir_seterr
(
"Output error: %s"
,
strerror
(
errno
));
return
1
;
}
return
0
;
}
if
((
dir
=
dir_read
(
&
fail
))
==
NULL
)
{
dir_setlasterr
(
dir_curpath
);
d
->
flags
|=
FF_ERR
;
dir_output
.
item
(
d
);
dir_output
.
item
(
NULL
);
if
(
dir_output
.
item
(
d
)
||
dir_output
.
item
(
NULL
))
{
dir_seterr
(
"Output error: %s"
,
strerror
(
errno
));
return
1
;
}
if
(
chdir
(
".."
))
{
dir_seterr
(
"Error going back to parent directory: %s"
,
strerror
(
errno
));
return
1
;
...
...
@@ -146,9 +150,15 @@ static int dir_scan_recurse(struct dir *d) {
if
(
fail
)
d
->
flags
|=
FF_ERR
;
dir_output
.
item
(
d
);
if
(
dir_output
.
item
(
d
))
{
dir_seterr
(
"Output error: %s"
,
strerror
(
errno
));
return
1
;
}
fail
=
dir_walk
(
dir
);
dir_output
.
item
(
NULL
);
if
(
dir_output
.
item
(
NULL
))
{
dir_seterr
(
"Output error: %s"
,
strerror
(
errno
));
return
1
;
}
/* Not being able to chdir back is fatal */
if
(
!
fail
&&
chdir
(
".."
))
{
...
...
@@ -190,10 +200,14 @@ static int dir_scan_item(struct dir *d) {
if
(
d
->
flags
&
FF_DIR
&&
!
(
d
->
flags
&
(
FF_ERR
|
FF_EXL
|
FF_OTHFS
)))
fail
=
dir_scan_recurse
(
d
);
else
if
(
d
->
flags
&
FF_DIR
)
{
dir_output
.
item
(
d
);
dir_output
.
item
(
NULL
);
}
else
dir_output
.
item
(
d
);
if
(
dir_output
.
item
(
d
)
||
dir_output
.
item
(
NULL
))
{
dir_seterr
(
"Output error: %s"
,
strerror
(
errno
));
fail
=
1
;
}
}
else
if
(
dir_output
.
item
(
d
))
{
dir_seterr
(
"Output error: %s"
,
strerror
(
errno
));
fail
=
1
;
}
return
fail
||
input_handle
(
1
);
}
...
...
@@ -260,9 +274,16 @@ int dir_scan_process() {
d
->
flags
|=
FF_ERR
;
stat_to_dir
(
d
,
&
fs
);
dir_output
.
item
(
d
);
fail
=
dir_walk
(
dir
);
dir_output
.
item
(
NULL
);
if
(
dir_output
.
item
(
d
))
{
dir_seterr
(
"Output error: %s"
,
strerror
(
errno
));
fail
=
1
;
}
if
(
!
fail
)
fail
=
dir_walk
(
dir
);
if
(
!
fail
&&
dir_output
.
item
(
NULL
))
{
dir_seterr
(
"Output error: %s"
,
strerror
(
errno
));
fail
=
1
;
}
}
while
(
dir_fatalerr
&&
!
input_handle
(
0
))
...
...
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