-
-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
g.tempfile: allow creation of temporary directories #4397
base: main
Are you sure you want to change the base?
Changes from 5 commits
647dccb
74de25b
16cd9d0
35f470a
8c61b63
e8f16d2
fb30b7b
98b27e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ int main(int argc, char *argv[]) | |
struct GModule *module; | ||
struct Option *pid; | ||
struct Flag *dry_run; | ||
struct Flag *directory; | ||
char *tempfile; | ||
int p; | ||
|
||
|
@@ -52,6 +53,13 @@ int main(int argc, char *argv[]) | |
dry_run->description = | ||
_("Dry run - don't create a file, just prints it's file name"); | ||
|
||
directory = G_define_flag(); | ||
directory->key = 'f'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. d is unfortunately used, but f is not great: folder, file, or directory? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I felt the same but had no better idea. I considered |
||
directory->description = | ||
_("Folder mode - create a temporary directory, not a file"); | ||
|
||
G_option_exclusive(dry_run, directory, NULL); | ||
|
||
G_disable_interactive(); | ||
if (G_parser(argc, argv)) | ||
exit(EXIT_FAILURE); | ||
|
@@ -63,8 +71,12 @@ int main(int argc, char *argv[]) | |
tempfile = G_tempfile_pid(p); | ||
|
||
/* create tempfile so next run of this program will create a unique name */ | ||
if (!dry_run->answer) | ||
close(creat(tempfile, 0666)); | ||
if (!dry_run->answer) { | ||
if (directory->answer) | ||
mkdir(tempfile, 0777); | ||
else | ||
close(creat(tempfile, 0666)); | ||
ninsbl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
fprintf(stdout, "%s\n", tempfile); | ||
|
||
exit(EXIT_SUCCESS); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to apply the changes in the markdown docs when updating the PR.