Cannot Make New Job From Empty Folder

Post Reply
DtM
Member
Posts: 26
Joined: Tue Aug 04, 2015 3:02 pm

Cannot Make New Job From Empty Folder

Post by DtM »

Hello,

I have a script where I am potentially producing multiple files, but want them to be contained in a single folder on output.

Once I have ascertained that I will be producing multiple files, I try to create a new job based on a temporary folder as such:

Code: Select all

// If multiple files are possible, then make a folder to keep the files in for output.
if (multipleFiles) {
    const tmpFolder = await tmp.dir({ unsafeCleanup: true });
    const newJobFolder = await job.createChild(tmpFolder.path);
}
This however returns the error: "Creating job error: No file attached".

If change tmp.dir to tmp.file, I do not get the error, but obviously that doesn't help me with my requirements.

I have tried running in debug, creating a breakpoint on the tmpFolder line and can confirm that the folder is definitely being created.

Looking at the documentation here I can see that I should be able to supply a file or folder, but the latter just does not seem to work.

Can anyone please give me some advice?

Many thanks.
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: Cannot Make New Job From Empty Folder

Post by freddyp »

You do not mention what package you are using, but I assume it is tmp.

You would think, so did I when I first used the package, that the path to the temporary file/folder would be in the property .path but if you use the package I think you use, it is .name. That is not very logical, but who said that variable/property/function naming in programming is logical? The non-existent property .path results in undefined and that is why there is a problem.

Side remark: this is a typical problem you get when coding in JavaScript. An object instance variable followed by a dot and a property (or a function for that matter) is syntactically correct so JavaScript will accept that during coding, but it can fail at run-time. If you worked in TypeScript you would notice during the coding that .path is not valid for that object.
DtM
Member
Posts: 26
Joined: Tue Aug 04, 2015 3:02 pm

Re: Cannot Make New Job From Empty Folder

Post by DtM »

Hi Freddy,

Apologies, my mistake for not clarifying - I am using tmp-promise which as the name would suggest is a wrapper for tmp that adds async await functionality.

Another thing that this wrapper does, is change the .name variable to .path (this also caught me off guard the first time I installed it!).

I have also confirmed this is the case in the debugger, putting a breakpoint after tmpFolder is created yields:

Code: Select all

tmpFolder: {
  path: "C:\\Users\\workflow\\AppData\\Local\\Temp\\2\\tmp-3280-q0JGV9zBr2Do",
  fd: 5,
  cleanup: function fn(...args) {
    return new Promise((resolve, reject) => {
      original.call(this, ...args, (err, ...values) => {
        if (err) {
          return reject(err);
        }
        if (argumentNames !== undefined && values.length > 1) {
          const obj = {};
          for (let i = 0; i < argumentNames.length; i++)
            obj[argumentNames[i]] = values[i];
          resolve(obj);
        } else {
          resolve(values[0]);
        }
      });
    });
  },
}
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: Cannot Make New Job From Empty Folder

Post by freddyp »

I have not tested it, so I will be assuming for a moment that creating a job from an empty folder does not work, and I think that is fine. At the moment you create a temporary folder, probably as opposed to a temporary file when multipleFiles == false, you have ascertained there will be multiple files.Well, put them there and only afterwards you create the child job from the folder.
owenj7920
Newbie
Posts: 1
Joined: Mon Nov 22, 2021 1:22 pm

Re: Cannot Make New Job From Empty Folder

Post by owenj7920 »

I am also facing this thing but resolved it by using gitignore on node.js. So I am writing all the codes which might be beneficial for everyone -
touch data/images/.gitignore
git add data/images/.gitignore
git commit -m "Add empty .gitignore to keep data/images around"
echo data >> .gitignore
git add .gitignore
git commit -m "Add data to .gitignore"

You can also follow the directory functions -
If you have directories dir1 and dir2, with dir1 containing fileA and fileB and dir2 containing fileC, git will commit the following (i.e. add the following to the index file):

dir1/fileA
dir1/fileB
dir2/fileC
In other words, neither dir1 nor dir2 are truly committed, they are simply constructed implicitly based on the paths of files contained inside them.

Now whether there are any deeper reasons for this or it simply made the implementation easier, I don't know.
Basically I needed these things for my best payroll and hr software, but still I am unable to do that properly. I have also a question can anyone from here give me the answers on that
What I usually do in such cases is to create a .gitkeep or a .gitignore file inside that directory:

First create the folder:
mkdir your_dir_here


Then create that empty .gitkeep file:
touch your_dir_here/.gitkeep


After that, you will be able to see the file with git status:
Output
Untracked files:
(use "git add <file>..." to include in what will be committed)

your_dir_here/


And add the file:
git add your_dir_here/


Finally commit as normal:
git commit -m "Adding Empty Directory"


The .gitkeep does not really have any special meaning for Git, but it will allow you to commit the empty directory in question!

Alternatively, you can use any other file. My advice is to be consistent throughout your project(s).
Post Reply