-
Notifications
You must be signed in to change notification settings - Fork 5
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
holo-files: Support patch files (#5) #42
Open
LukeShu
wants to merge
6
commits into
holocm:master
Choose a base branch
from
LukeShu:patch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dc0aebd
holo-files/impl.Resource: Pre-compute the disambiguator and entityPath.
LukeShu cf1d60b
holo-files: Turn Resource into an interface, split the implementation.
LukeShu aa26621
holo-files: Split resource.go into multiple files, tidy.
LukeShu 610d23e
util/dump-to-tree.sh: Correctly handle backslashes in file contents.
LukeShu 52364c3
doc/holo-files: Refactor wording in anticipation of what is coming.
LukeShu d3c9cba
holo-files: Implement .patch files.
LukeShu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/******************************************************************************* | ||
* | ||
* Copyright 2015 Stefan Majewsky <[email protected]> | ||
* Copyright 2017 Luke Shumaker <[email protected]> | ||
* | ||
* This file is part of Holo. | ||
* | ||
* Holo is free software: you can redistribute it and/or modify it under the | ||
* terms of the GNU General Public License as published by the Free Software | ||
* Foundation, either version 3 of the License, or (at your option) any later | ||
* version. | ||
* | ||
* Holo is distributed in the hope that it will be useful, but WITHOUT ANY | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
* A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* Holo. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*******************************************************************************/ | ||
|
||
package impl | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
|
||
"github.com/holocm/holo/cmd/holo-files/internal/common" | ||
) | ||
|
||
// Holoscript is a Resource that is a script that edits the current | ||
// version of the entity. | ||
type Holoscript struct{ rawResource } | ||
|
||
// ApplicationStrategy implements the Resource interface. | ||
func (resource Holoscript) ApplicationStrategy() string { return "passthru" } | ||
|
||
// DiscardsPreviousBuffer implements the Resource interface. | ||
func (resource Holoscript) DiscardsPreviousBuffer() bool { return false } | ||
|
||
// ApplyTo implements the Resource interface. | ||
func (resource Holoscript) ApplyTo(entityBuffer common.FileBuffer) (common.FileBuffer, error) { | ||
//application of a holoscript requires file contents | ||
entityBuffer, err := entityBuffer.ResolveSymlink() | ||
if err != nil { | ||
return common.FileBuffer{}, err | ||
} | ||
|
||
//run command, fetch result file into buffer (not into the entity | ||
//directly, in order not to corrupt the file there if the script run fails) | ||
var stdout bytes.Buffer | ||
cmd := exec.Command(resource.Path()) | ||
cmd.Stdin = strings.NewReader(entityBuffer.Contents) | ||
cmd.Stdout = &stdout | ||
cmd.Stderr = os.Stderr | ||
err = cmd.Run() | ||
if err != nil { | ||
return common.FileBuffer{}, fmt.Errorf("execution of %s failed: %s", resource.Path(), err.Error()) | ||
} | ||
|
||
//result is the stdout of the script | ||
entityBuffer.Mode &^= os.ModeType | ||
entityBuffer.Contents = stdout.String() | ||
return entityBuffer, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/******************************************************************************* | ||
* | ||
* Copyright 2015 Stefan Majewsky <[email protected]> | ||
* Copyright 2017 Luke Shumaker <[email protected]> | ||
* | ||
* This file is part of Holo. | ||
* | ||
* Holo is free software: you can redistribute it and/or modify it under the | ||
* terms of the GNU General Public License as published by the Free Software | ||
* Foundation, either version 3 of the License, or (at your option) any later | ||
* version. | ||
* | ||
* Holo is distributed in the hope that it will be useful, but WITHOUT ANY | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
* A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* Holo. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*******************************************************************************/ | ||
|
||
package impl | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/holocm/holo/cmd/holo-files/internal/common" | ||
) | ||
|
||
// StaticResource is a Resource that is a plain static file that | ||
// replaces the current version of the entity. | ||
type StaticResource struct{ rawResource } | ||
|
||
// ApplicationStrategy implements the Resource interface. | ||
func (resource StaticResource) ApplicationStrategy() string { return "apply" } | ||
|
||
// DiscardsPreviousBuffer implements the Resource interface. | ||
func (resource StaticResource) DiscardsPreviousBuffer() bool { return true } | ||
|
||
// ApplyTo implements the Resource interface. | ||
func (resource StaticResource) ApplyTo(entityBuffer common.FileBuffer) (common.FileBuffer, error) { | ||
resourceBuffer, err := common.NewFileBuffer(resource.Path()) | ||
if err != nil { | ||
return common.FileBuffer{}, err | ||
} | ||
entityBuffer.Contents = resourceBuffer.Contents | ||
entityBuffer.Mode = (entityBuffer.Mode &^ os.ModeType) | (resourceBuffer.Mode & os.ModeType) | ||
|
||
//since Linux disregards mode flags on symlinks and always reports 0777 perms, | ||
//normalize the mode thusly to make FileBuffer.EqualTo() work reliably | ||
if entityBuffer.Mode&os.ModeSymlink != 0 { | ||
entityBuffer.Mode = os.ModeSymlink | os.ModePerm | ||
} | ||
return entityBuffer, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: "but are inherited"