-
Notifications
You must be signed in to change notification settings - Fork 392
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
Resolve full path of pcap which starts with '~' #607
Conversation
4bda201
to
96ae0c4
Compare
Really wish this feature gets added in next release. To that end, any suggestions/comments to code implementation are welcome, I will try my best to cater them, |
Hi @wdoekes , could you please take a look at this PR when you find some time and offer your suggestions, if any? I am new to github community, so please also do let me know if a direct ping is inappropriate, I will refrain from in future. |
Maybe add expanduser(). That way Chatgpt was helpful enough to give me this ("can you show me a C implementation of python os.path.expanduser?"): #include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
char* expanduser(char* path) {
if (path == NULL) {
return NULL;
}
if (path[0] == '~') {
char* homedir = NULL;
if (path[1] == '\0' || path[1] == '/') {
homedir = getenv("HOME");
} else {
struct passwd* pw = getpwnam(path+1);
if (pw != NULL) {
homedir = pw->pw_dir;
}
}
if (homedir != NULL) {
char* expanded = malloc(strlen(homedir) + strlen(path));
sprintf(expanded, "%s%s", homedir, path+1);
return expanded;
}
}
return strdup(path);
} with these caveats:
(I'd probably prefer a version with a provided buffer.) (Also, it uses a non-reentrant |
sprintf(expanded, "%s%s", homedir, path+1); Hehe. This can't possibly work for (Also.. no malloc() NULL check. But I don't want any malloc here anyway.) |
Thankyou @wdoekes for your suggestions, I have added support for |
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.
Please check my suggestion for the expand_user_path invocation. It should not be optional based on ~, but always be called directly.
FYI: I moved find_file() to fileutil.c where is used by both pcap and rtpstream file lookups. |
Sorry for inactivity, I have applied the changes you suggested, and will verify the them over the different cases you mentioned tomorrow |
Don't hardcode retry counter max value.
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.3.3 to 4.3.4. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](actions/upload-artifact@v4.3.3...v4.3.4) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]>
Hi, apologies for inactivity. I have fixed the regression test failures. |
LGTM and it passes the tests. |
Thanks for the style fixes 👍 I'm unfortunately unable to review this timely. Unassigning. Leaving the review+merge to someone else. E.g. @lemenkov |
src/fileutil.c
Outdated
struct passwd pwd; | ||
struct passwd* result; | ||
size_t bufsize = sysconf(_SC_GETPW_R_SIZE_MAX); | ||
char buffer[bufsize + 1]; |
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.
Dynamic array size is a GNU extension. Do we have this elsewhere in the codebase?
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.
Thanks, I was not aware of this and couldn't find such examples in the codebase either. Now using malloc()
reluctantly.
This reverts commit 9333f8d.
… soon as it is not used anymore
Hi @orgads could you please review the updated diff when you get some time. Thankyou. |
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.
Thanks for the reminder.
I approve, just reply on the NULL comment and then I'll merge.
You have conflicts. Please rebase. |
expand paths like '~/path/to/file.pcap' to '/home/myuser/path/to/file.pcap'