# Using rake package task- suppressing initial segment of path

**URL:** <https://www.ruby-forum.com/t/using-rake-package-task-suppressing-initial-segment-of-path/67284>\
**Category:** Ruby\
**Created:** [September 1, 2006, 9:22pm UTC](https://www.ruby-forum.com/t/using-rake-package-task-suppressing-initial-segment-of-path/67284 "2006-09-01T21:22:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dandante](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9fc29f/32.png) [@dandante](https://www.ruby-forum.com/u/dandante)\
**Post date:** [September 1, 2006, 9:22pm UTC](https://www.ruby-forum.com/t/using-rake-package-task-suppressing-initial-segment-of-path/67284/1 "2006-09-01T21:22:57Z")

</div>

I have the following trivial bit of code, just to help me figure out  
how to create a more usable tarball:

require ‘rake/packagetask’  
Rake::PackageTask.new(‘WCV’, :noversion) do |p|  
p.need\_tar\_gz = true  
p.package\_files.include(“README”)  
end  
when I run “rake package”, it creates a pkg directory  
and a tarball in that directory called “wcv.tar.gz”.  
when I do “tar ztf pkg/wcv.tar.gz” I see this:

wcv/  
wcv/README

I need for the initial “wcv” **not** to be included.  
In other words, when I run “tar ztf pkg/wcv.tar.gz” I want to see:  
README

Can this be done?

Thx

---

<div class="post-metadata">

**Author:** ![dandante](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9fc29f/32.png) [@dandante](https://www.ruby-forum.com/u/dandante)\
**Post date:** [September 1, 2006, 11:03pm UTC](https://www.ruby-forum.com/t/using-rake-package-task-suppressing-initial-segment-of-path/67284/2 "2006-09-01T23:03:50Z")

</div>

Dan T. wrote:  
[…]

> I need for the initial “wcv” **not** to be included.  
> In other words, when I run “tar ztf pkg/wcv.tar.gz” I want to see:  
> README

Yikes! I hate when packages dump their contained files intermingled  
with files in the current directory. That’s why PackageTask does it  
that way it does.

However, read on if you feel you have a legitimate need.

> Can this be done?

The package task does not do that, nor is there a straightforward way to  
configure it to do so.

However …

The guts of the package task are not that complex. It is just running  
tar over the list of files it has collected. If you don’t want to redo  
everything, you can let the package task build the directory and then  
just add your own task to build the tar file.

Assume your project is myproj, version 1.2.3

Add this task:

file “myproj-1.2.3.tgz” =\> “pkg/myproj-1.2.3” do  
chdir(“pkg/pkg/myproj-1.2.3”) do  
sh %{tar zcvf …/…/myproj-1.2.3.tgz \*}  
end  
end

This will create a tgz file in the root of your project (rather than in  
the pkg directory like the package task does). Typing:

```
rake myproj-1.2.3.tgz

```

will do the trick.

Does this help?

– Jim W.

---

<div class="post-metadata">

**Author:** ![dandante](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9fc29f/32.png) [@dandante](https://www.ruby-forum.com/u/dandante)\
**Post date:** [September 2, 2006, 12:19am UTC](https://www.ruby-forum.com/t/using-rake-package-task-suppressing-initial-segment-of-path/67284/3 "2006-09-02T00:19:52Z")

</div>

Jim W. wrote:

> Dan T. wrote:  
> […]
> 
> > I need for the initial “wcv” **not** to be included.  
> > In other words, when I run “tar ztf pkg/wcv.tar.gz” I want to see:  
> > README
> 
> Yikes! I hate when packages dump their contained files intermingled  
> with files in the current directory. That’s why PackageTask does it  
> that way it does.

Yeah…but I’m not creating a package. I have a specialized need.

> Assume your project is myproj, version 1.2.3
> 
> Add this task:
> 
> file “myproj-1.2.3.tgz” =\> “pkg/myproj-1.2.3” do  
> chdir(“pkg/pkg/myproj-1.2.3”) do  
> sh %{tar zcvf …/…/myproj-1.2.3.tgz \*}  
> end  
> end
> 
> This will create a tgz file in the root of your project (rather than in  
> the pkg directory like the package task does). Typing:
> 
> ```
> rake myproj-1.2.3.tgz
> 
> ```
> 
> will do the trick.
> 
> Does this help?

Yes, that works, thanks. I ended up just doing it without the Package  
task, and just using Find.find to generate the list of files, looping  
through it to weed out my complicated exclusions.
