From 20dc71dcfd433ac738c05c927cb75701e9cc4fec Mon Sep 17 00:00:00 2001 From: yhoogstrate Date: Wed, 30 Oct 2019 16:54:25 +0100 Subject: [PATCH] sav --- include/utils.hpp | 4 ++++ src/fastafs.cpp | 3 ++- src/fuse.cpp | 6 ++++-- src/lsfastafs.cpp | 8 +++++++- src/ucsc2bit.cpp | 3 ++- src/utils.cpp | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 51 insertions(+), 5 deletions(-) diff --git a/include/utils.hpp b/include/utils.hpp index 0b3b4842..da6efd2f 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -17,3 +17,7 @@ std::string std_string_nullbyte_safe(char *, size_t, size_t); std::string std_string_nullbyte_safe(char *, size_t); bool is_fasta_file(char *filename); + +std::string basename_cpp(std::string); +std::string realpath_cpp(std::string); + diff --git a/src/fastafs.cpp b/src/fastafs.cpp index 4600dfce..d786e02b 100644 --- a/src/fastafs.cpp +++ b/src/fastafs.cpp @@ -495,7 +495,8 @@ void fastafs::load(std::string afilename) if(file.is_open()) { // if a user can't compile this line, please replace it with C's // 'realpath' function and delete/free afterwards and send a PR - this->filename = std::filesystem::canonical(afilename);// this path must be absolute because if stuff gets send to FUSE, paths are relative to the FUSE process and probably systemd initialization + //this->filename = std::filesystem::canonical(afilename);// this path must be absolute because if stuff gets send to FUSE, paths are relative to the FUSE process and probably systemd initialization + this->filename = realpath_cpp(afilename); size = file.tellg(); diff --git a/src/fuse.cpp b/src/fuse.cpp index 228a0c43..d71ceed6 100644 --- a/src/fuse.cpp +++ b/src/fuse.cpp @@ -478,7 +478,8 @@ fuse_instance *parse_args(int argc, char **argv, char **argv_fuse) std::string name; // prefix name of mounted fasta dict 2bit and fai files if(fname.size() == 0) { // invalid mount argument, don't bind fastafs object fname = std::string(argv[mount_target_arg]); - name = std::filesystem::path(fname).filename(); + //name = std::filesystem::path(fname).filename(); + name = basename_cpp(fname); // remove .fastafs suffix size_t lastindex = name.find_last_of("."); @@ -492,7 +493,8 @@ fuse_instance *parse_args(int argc, char **argv, char **argv_fuse) fi->f->load(fname); fi->cache = fi->f->init_ffs2f(fi->padding, true);// allow mixed case } else { - std::string basename = std::filesystem::path(std::string(argv[mount_target_arg])).filename(); + std::string basename = basename_cpp(std::string(argv[mount_target_arg])); + //std::string basename = std::filesystem::path(std::string(argv[mount_target_arg])).filename(); fi->u2b = new ucsc2bit(basename);// useses basename as prefix for filenames to mount: hg19.2bit -> hg19.2bit.fa fi->u2b->load(std::string(argv[mount_target_arg])); diff --git a/src/lsfastafs.cpp b/src/lsfastafs.cpp index 363ab99c..daeb2725 100644 --- a/src/lsfastafs.cpp +++ b/src/lsfastafs.cpp @@ -1,10 +1,12 @@ #include +#include #include #include #include #include +#include "utils.hpp" #include "config.hpp" @@ -57,7 +59,11 @@ std::unordered_multimap > get_f strstr(mount_dir, arg) != NULL)) { std::string fn = std::string(mount_dir); - std::string basename = std::filesystem::path(fn).filename(); + + std::string basename = basename_cpp(fn); + //std::string basename = std::filesystem::path(fn).filename(); + std::cout << "basename: " << basename << "\n"; + std::string dict_fn = std::string(mount_dir) + "/" + basename + ".dict"; if(getxattr(mount_dir, FASTAFS_FILE_XATTR_NAME.c_str(), xattr_fastafs_file, 255) != -1 diff --git a/src/ucsc2bit.cpp b/src/ucsc2bit.cpp index 39a6479a..43f06ae2 100644 --- a/src/ucsc2bit.cpp +++ b/src/ucsc2bit.cpp @@ -239,7 +239,8 @@ void ucsc2bit::load(std::string afilename) if(file.is_open()) { // if a user can't compile this line, please replace it with C's // 'realpath' function and delete/free afterwards and send a PR - this->filename = std::filesystem::canonical(afilename);// this path must be absolute because if stuff gets send to FUSE, paths are relative to the FUSE process and probably systemd initialization + //this->filename = std::filesystem::canonical(afilename);// this path must be absolute because if stuff gets send to FUSE, paths are relative to the FUSE process and probably systemd initialization + this->filename = realpath_cpp(afilename); if(file.tellg() < 16) { file.close(); diff --git a/src/utils.cpp b/src/utils.cpp index db8c7c39..0c8c8601 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1,4 +1,6 @@ +#include +#include #include #include @@ -170,3 +172,33 @@ bool is_fasta_file(char *filename) return false; } + +// https://www.systutorials.com/241216/how-to-get-the-directory-path-and-file-name-from-a-absolute-path-in-c-on-linux/ +// https://stackoverflow.com/questions/38456127/what-is-the-value-of-cplusplus-for-c17 - THEN use std::filesystem::path(filename).filename(); +std::string basename_cpp(std::string fn) { + //char* ts1 = strdup(local_file); + char* ts2 = strdup(fn.c_str()); + + //char* dir = dirname(ts1); + char* filename = basename(ts2); + std::string filenamepp = std::string(filename); + + printf("basename: [%s]\n", filename); + std::cout << "basenamepp: |" << filenamepp << "|\n"; + + return filenamepp; +} + + +// https://www.linuxquestions.org/questions/programming-9/how-to-get-the-full-path-of-a-file-in-c-841046/ +// https://stackoverflow.com/questions/38456127/what-is-the-value-of-cplusplus-for-c17 - THEN use std::filesystem::canonical(filename) +std::string realpath_cpp(std::string fn) { + std::string out = "asd"; + char *path = realpath(fn.c_str(), NULL); + printf("realpath: [%s]\n", path); + + std::string realpathpp = std::string(path); + std::cout << "realpath: |" << realpathpp << "|\n"; + + return realpathpp; +}