Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some bugs in code in "file backup" chapter #52

Open
masiacra opened this issue Jun 11, 2024 · 2 comments
Open

Some bugs in code in "file backup" chapter #52

masiacra opened this issue Jun 11, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@masiacra
Copy link

Good day.
In backup.js there are 2 function in which you use keyword 'await' probably incorrectly. These are copyFiles and saveManifest.
You don't use another related keyword 'await' so it is first hint.
I think it would be better to omit async in these two functions and return simple promises. In this case you will get:

const copyFiles = (dst, needToCopy) => {
  const promises = Object.keys(needToCopy).map((hash) => {
    const srcPath = needToCopy[hash];
    const dstPath = `${dst}/${hash}.bck`;
    return fs.copyFile(srcPath, dstPath); // you probably miss await in this line
  });

  return Promise.all(promises);
};

const saveManifest = (dst, timestamp, pathHash) => {
  pathHash = pathHash.sort();
  const content = pathHash
    .map(([path, hash]) => {
      return `${path}/${hash}`;
    })
    .join("\n");

  const manifest = `${dst}/${timestamp}.csv`;

  return fs.writeFile(manifest, content, { encoding: "utf-8" }); // and probably miss await in this line
}; 

Thank you for you job and sorry for my poor english

@gvwilson
Copy link
Owner

thanks very much for the bug report @masiacra (and your English is fine :-) ). I'll try to post a fix some time in the next few weeks - cheers!

@masiacra
Copy link
Author

Thank you for your job. Great book)

@gvwilson gvwilson self-assigned this Jul 16, 2024
@gvwilson gvwilson added the bug Something isn't working label Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants