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

add option: create non-existing files before updating existing files #100

Merged
merged 2 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ deploy:
rsh: <remote shell>
verbose: [true|false] # Default is true
ignore_errors: [true|false] # Default is false
create_before_update: [true|false] # Default is false
```

- **host**: Address of remote host
Expand All @@ -38,6 +39,7 @@ deploy:
- **rsh**: Specify the remote shell to use
- **verbose**: Display verbose messages
- **ignore_errors**: Ignore errors
- **create_before_update**: First create non-existing files, then update existing files

## License

Expand Down
17 changes: 15 additions & 2 deletions lib/deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ module.exports = function(args) {
help += ' args: <rsync args>\n';
help += ' rsh: <remote shell>\n';
help += ' verbose: [true|false] # Default is true\n';
help += ' ignore_errors: [true|false] # Default is false\n\n';
help += ' ignore_errors: [true|false] # Default is false\n';
help += ' create_before_update: [true|false] # Default is false\n\n';
help += 'For more help, you can check the docs: ' + color.underline('https://hexo.io/docs/deployment.html');

console.log(help);
Expand All @@ -30,6 +31,7 @@ module.exports = function(args) {
if (!Object.prototype.hasOwnProperty.call(args, 'delete')) args.delete = true;
if (!Object.prototype.hasOwnProperty.call(args, 'verbose')) args.verbose = true;
if (!Object.prototype.hasOwnProperty.call(args, 'ignore_errors')) args.ignore_errors = false;
if (!Object.prototype.hasOwnProperty.call(args, 'create_before_update')) args.create_before_update = false;

const params = [
'-az',
Expand All @@ -51,5 +53,16 @@ module.exports = function(args) {
if (args.delete) params.unshift('--delete');
if (args.args) params.unshift(args.args);

return spawn('rsync', params, {verbose: true});
if (args.create_before_update) {
// Create non-existing files before updating existing files.
// New files may be large documents, images and media, and we want to upload them first before updating links to them in the existing pages.
// Otherwise, the links may be updated first and temporarily point to new files that have not been uploaded yet.
params.unshift('--ignore-existing');
return spawn('rsync', params, {verbose: true}).then(() => {
params.shift();
return spawn('rsync', params, {verbose: true});
});
} else {
return spawn('rsync', params, {verbose: true});
}
};