You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
targo only provides methods to create and extract tar archives from directories. If I understand your use-case correctly, what you would like to do is flatten the content of a directory at the root of the archive. Is that correct? Or would you simply have the possibility to create a tar archive out of a number of files used as tar function input?
What I would like is the possibility to flatten the content of the target directory at the root of the archive yes.
I made some tests with your code and I'm not able to achieve this. However, I more or less rewrite the targo.Create function more naively and in a simpler way (without symlink treatment) and I have what I want. But I don't really understand why in targo function case a directory is created inside the tar and in my rewrite, the content is flatten. I'll investigate a little bit more but it's very strange to me.
Do you think this use-case could enter in the scope of targo ? If yes, I'll be happy to submit a pull request once I find how to achieve it.
What about a variadic create function which would directly take the path to files as argument? Would that fit your use case? Because I am not fond of the idea of flattening the content of a directory at the root of the tar archive. Modifying the original structure of the document is not a good behavior IMHO.
If you do something like what I propose, considering you handle all the cases including symlink, I'll be happy to merge your pull request. Also, make sure to provide comprehensive tests so we know that the function behaves as expected.
Sorry for the misunderstanding but what I meant is not to flatten all content in the tar. What I would like is just to avoid the first directory given in argument in the tar but to keep the rest of the structure.
Something like :
somedir/
..file1
..somesubdir/
....file2
becomes :
sometar/
..file1
..somesubdir/
....file2
The equivalent in linux command line would be tar -cf somedir.tar path/to/somedir/* instead of tar -cf somedir.tar path/to/somedir.
But like I said earlier, I have trouble finding what in the code of targo.Create is making the root directory to be present in the tar or what I'm doing that removing it.
I'm confused now. When you do tar -cf somedir.tar path/to/somedir/* what actually happens is that the wildcard argument is expanded to the files and directories contained in somedir, right? You are in fact, in this case, providing multiple arguments to the tar utility. Hence, my proposition of adding a variadic create function still holds, right?
FYI, targo is not "explicitly adding a root directory". You give it a directory as argument, hence you will find that same directory, including its content, in the resulting tar archive.
Yeah your proposition is perfect. The call that I would like to make is something along the lines of targo.CreateFromFileList('path/to/somedir'; 'path/to/sometar').
I understand the functionality of targo and I'm totally ok with it. I'm just saying that I have trouble to find in the code of targo.Create what causes this directory to be added in the tar and therefore to write a code that doesn't add this directory.
As I already tried to explain, targo simply "walks" through the directory given as argument and recreates this exact structure in the resulting tar archive. The root directory is not treated differently, as explained in the documentation of the filepath.Walk function.
Excuse me if I wasn't entirely clear about my answers. Basically, I had two calls of apparently the same code doing different results, and I was trying to find out why.
I finally have found what causes the difference between my hacked code and yours. The dirpath that I used calling your function was targo.Create("/tmp/sometar.tar", "/tmp/somedir/") and calling mine was targo.Create("/tmp/sometar.tar", "/tmp/somedir"). Note the trailing slash difference.
The function causing the behavior of these two call is ´filepath.Dir(dirpath) :
filepath.Dir("/tmp/somedir/") => /tmp/somedir
filepath.Dir("/tmp/somedir") => /tmp
I guess its because filepath.Dir consider the last directory of the first call to be '.' and the second call to be somedir.
So, the conclusion is that I can use targo.Create for my use case without modifying anything to targo but I don't know if it was you intention to have such behavior. Maybe it's worth to document this behavior ?
Activity
rolinh commentedon Feb 18, 2016
Hi,
targoonly provides methods to create and extract tar archives from directories. If I understand your use-case correctly, what you would like to do is flatten the content of a directory at the root of the archive. Is that correct? Or would you simply have the possibility to create a tar archive out of a number of files used as tar function input?AlbinOS commentedon Feb 18, 2016
Hi Rolinh and thanks for you reply.
What I would like is the possibility to flatten the content of the target directory at the root of the archive yes.
I made some tests with your code and I'm not able to achieve this. However, I more or less rewrite the targo.Create function more naively and in a simpler way (without symlink treatment) and I have what I want. But I don't really understand why in targo function case a directory is created inside the tar and in my rewrite, the content is flatten. I'll investigate a little bit more but it's very strange to me.
Do you think this use-case could enter in the scope of targo ? If yes, I'll be happy to submit a pull request once I find how to achieve it.
rolinh commentedon Feb 18, 2016
What about a variadic
createfunction which would directly take the path to files as argument? Would that fit your use case? Because I am not fond of the idea of flattening the content of a directory at the root of the tar archive. Modifying the original structure of the document is not a good behavior IMHO.If you do something like what I propose, considering you handle all the cases including symlink, I'll be happy to merge your pull request. Also, make sure to provide comprehensive tests so we know that the function behaves as expected.
AlbinOS commentedon Feb 18, 2016
Sorry for the misunderstanding but what I meant is not to flatten all content in the tar. What I would like is just to avoid the first directory given in argument in the tar but to keep the rest of the structure.
Something like :
becomes :
The equivalent in linux command line would be
tar -cf somedir.tar path/to/somedir/*instead oftar -cf somedir.tar path/to/somedir.But like I said earlier, I have trouble finding what in the code of targo.Create is making the root directory to be present in the tar or what I'm doing that removing it.
rolinh commentedon Feb 18, 2016
I'm confused now. When you do
tar -cf somedir.tar path/to/somedir/*what actually happens is that the wildcard argument is expanded to the files and directories contained insomedir, right? You are in fact, in this case, providing multiple arguments to thetarutility. Hence, my proposition of adding a variadic create function still holds, right?FYI,
targois not "explicitly adding a root directory". You give it a directory as argument, hence you will find that same directory, including its content, in the resulting tar archive.AlbinOS commentedon Feb 18, 2016
Yeah your proposition is perfect. The call that I would like to make is something along the lines of
targo.CreateFromFileList('path/to/somedir'; 'path/to/sometar').I understand the functionality of targo and I'm totally ok with it. I'm just saying that I have trouble to find in the code of targo.Create what causes this directory to be added in the tar and therefore to write a code that doesn't add this directory.
rolinh commentedon Feb 18, 2016
Yeah, that would do it then :)
As I already tried to explain,
targosimply "walks" through the directory given as argument and recreates this exact structure in the resulting tar archive. The root directory is not treated differently, as explained in the documentation of the filepath.Walk function.AlbinOS commentedon Feb 18, 2016
Excuse me if I wasn't entirely clear about my answers. Basically, I had two calls of apparently the same code doing different results, and I was trying to find out why.
I finally have found what causes the difference between my hacked code and yours. The dirpath that I used calling your function was
targo.Create("/tmp/sometar.tar", "/tmp/somedir/")and calling mine wastargo.Create("/tmp/sometar.tar", "/tmp/somedir"). Note the trailing slash difference.The function causing the behavior of these two call is
´filepath.Dir(dirpath):filepath.Dir("/tmp/somedir/")=>/tmp/somedirfilepath.Dir("/tmp/somedir")=>/tmpI guess its because filepath.Dir consider the last directory of the first call to be
'.'and the second call to besomedir.So, the conclusion is that I can use targo.Create for my use case without modifying anything to targo but I don't know if it was you intention to have such behavior. Maybe it's worth to document this behavior ?
rolinh commentedon Feb 18, 2016
Great.
It could be useful, yes. I'll happily merge a pull request if you do so 😉
Added examples for rolinh#1
Documenting the possible behavior of Create
rolinh commentedon Feb 20, 2016
Resolved by #2. Thanks @AlbinOS !