# Pijul add of a directory says it's a file

**URL:** <https://discourse.pijul.org/t/pijul-add-of-a-directory-says-its-a-file/433>\
**Category:** Question\
**Created:** [November 17, 2019, 8:58pm UTC](https://discourse.pijul.org/t/pijul-add-of-a-directory-says-its-a-file/433 "2019-11-17T20:58:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fintohaps](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/fintohaps/32/211_2.png) [@fintohaps](https://discourse.pijul.org/u/fintohaps)\
**Post date:** [November 17, 2019, 8:58pm UTC](https://discourse.pijul.org/t/pijul-add-of-a-directory-says-its-a-file/433/1 "2019-11-17T20:58:57Z")

</div>

I decided to play around with Pijul this evening and was going through the getting started document.

So I created a new Rust project called `pijul-test` and moved onto adding the files. But something caught me by surprise. When I ran this action:

```auto
pijul add Cargo.toml src/

```

It added `src` as a file as you can see below:

```auto
λ ~/Developer/pijul-test/ pijul status            
On branch master

Changes not yet recorded:
  (use "pijul record ..." to record a new patch)

        new file: Cargo.toml
        new file: src

Untracked files:
  (use "pijul add <file>..." to track them)

        src/main.rs

```

I usually do do `git add directory` to add everything under `directory` and I thought it would be the same with Pijul. So now I’m curious.

1. Why did Pijul assume it was a file?
2. Why didn’t Pijul check that indeed was a file?
3. How is `src` represented in the patch now that I recorded it?

Looking forward to getting some answers 😁 and looking forward, even more, to playing around with Pijul and learning about it 😍

---

<div class="post-metadata">

**Author:** ![pmeunier](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/pmeunier/32/4_2.png) [@pmeunier](https://discourse.pijul.org/u/pmeunier)\
**Post date:** [November 17, 2019, 9:47pm UTC](https://discourse.pijul.org/t/pijul-add-of-a-directory-says-its-a-file/433/2 "2019-11-17T21:47:28Z")

</div>

Hi! Welcome. I believe this is just a minor terminology error in the `patch` command, your directory was almost certainly recorded as a directory.  
If you want to add an entire directory recursively, `pijul add --recursive` can do that.

---

<div class="post-metadata">

**Author:** ![fintohaps](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/fintohaps/32/211_2.png) [@fintohaps](https://discourse.pijul.org/u/fintohaps)\
**Post date:** [November 18, 2019, 10:23am UTC](https://discourse.pijul.org/t/pijul-add-of-a-directory-says-its-a-file/433/3 "2019-11-18T10:23:52Z")

</div>

Thanks for the reply and the welcome 😊

> your directory was almost certainly recorded as a directory.

Cool, that’s good to know! Would it be worth me digging into the implementation a bit and seeing if I can change the message to say that Pijul is adding a directory? 🤔

> If you want to add an entire directory recursively, `pijul add --recursive` can do that.

Good to know! I still need to browse through the rest of the docs 🙂

---

<div class="post-metadata">

**Author:** ![pmeunier](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/pmeunier/32/4_2.png) [@pmeunier](https://discourse.pijul.org/u/pmeunier)\
**Post date:** [November 18, 2019, 11:49am UTC](https://discourse.pijul.org/t/pijul-add-of-a-directory-says-its-a-file/433/4 "2019-11-18T11:49:44Z")

</div>

> [@fintohaps](#):
>
> Would it be worth me digging into the implementation a bit and seeing if I can change the message to say that Pijul is adding a directory?

This is actually a good first bug! I’m not particularly happy about how libpijul is organised (I’m currently rewriting it from scratch), but if you look at `libpijul/src/backend/file_header.rs`, you’ll see the type `FileMetadata` defined, just before a constant `DIR_BIT` is defined.

Actually, in Pijul, file names are stored prefixed by a 16 bit integer indicating (1) permissions, on the 9 least-significant bits, and (2) whether it’s a file or a directory, on the 10th LSB.

So, if you look at the `patch` command in `pijul/src/commands/patch.rs`, there’s a number of calls to the `get_file_names` method that seem to return a tuple, but the first component is ignored. I believe that first component is the 16-bit “permissions” info (I might be wrong).

---

<div class="post-metadata">

**Author:** ![fintohaps](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.pijul.org/fintohaps/32/211_2.png) [@fintohaps](https://discourse.pijul.org/u/fintohaps)\
**Post date:** [November 26, 2019, 9:27pm UTC](https://discourse.pijul.org/t/pijul-add-of-a-directory-says-its-a-file/433/5 "2019-11-26T21:27:03Z")

</div>

I did some digging around and grepped for text. I came up with a patch here [https://nest.pijul.com/pijul\_org/pijul/discussions/437](https://nest.pijul.com/pijul_org/pijul/discussions/437). Hopefully it’s a good starting point 🙏
