8000 fix: no rebuild on second serve by lumtis · Pull Request #714 · ignite/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: no rebuild on second serve #714

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

Merged
merged 2 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 11 additions & 10 deletions starport/pkg/dirchange/dirchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,24 @@ func SaveDirChecksum(workdir string, paths []string, checksumSavePath string, ch

// HasDirChecksumChanged computes the md5 checksum of the provided paths (directories or files)
// and compare it with the current saved checksum
// If the checksum is different, the new checksum is saved
// Return true if the checksum file doesn't exist yet and if checksumSavePath directory doesn't exist, it is created
// Return true if the checksum file doesn't exist yet
// paths are relative to workdir, if workdir is empty string paths are absolute
func HasDirChecksumChanged(workdir string, paths []string, checksumSavePath string, checksumName string) (bool, error) {
checksum, err := checksumFromPaths(workdir, paths)
if err != nil {
return false, err
}

// create directory if needed
if err := os.MkdirAll(checksumSavePath, 0700); err != nil && !os.IsExist(err) {
return false, err
}

checksumFilePath := filepath.Join(checksumSavePath, checksumName)
if _, err := os.Stat(checksumFilePath); os.IsNotExist(err) {
return true, ioutil.WriteFile(checksumFilePath, checksum, 0644)
return true, nil
} else if err != nil {
return false, nil
}

// Compute checksum
checksum, err := checksumFromPaths(workdir, paths)
if err != nil {
return false, err
}

// Compare checksums
Expand All @@ -59,7 +60,7 @@ func HasDirChecksumChanged(workdir string, paths []string, checksumSavePath stri
}

// The checksum has changed
return true, ioutil.WriteFile(checksumFilePath, checksum, 0644)
return true, nil
}

// checksumFromPaths computes the md5 checksum from the provided paths
Expand Down
13 changes: 2 additions & 11 deletions starport/pkg/dirchange/dirchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,18 @@ func TestHasDirChecksumChanged(t *testing.T) {
require.NoError(t, err)
require.False(t, changed)

// Return true and create the checksum file if it doesn't exist
// Return true if it doesn't exist
newSaveDir, err := ioutil.TempDir(tempDir, TmpPattern)
require.NoError(t, err)
defer os.RemoveAll(newSaveDir)
changed, err = HasDirChecksumChanged("", paths, newSaveDir, ChecksumFile)
require.NoError(t, err)
require.True(t, changed)
require.FileExists(t, filepath.Join(newSaveDir, ChecksumFile))
fileContent, err = ioutil.ReadFile(filepath.Join(newSaveDir, ChecksumFile))
require.NoError(t, err)
require.Equal(t, newChecksum, fileContent)

// Return true and rewrite the checksum if it has been changed
// Return true if it has been changed
err = ioutil.WriteFile(filepath.Join(dir21, "bar"), randomBytes(20), 0644)
require.NoError(t, err)
changed, err = HasDirChecksumChanged("", paths, saveDir, ChecksumFile)
require.NoError(t, err)
require.True(t, changed)
fileContent, err = ioutil.ReadFile(filepath.Join(saveDir, ChecksumFile))
require.NoError(t, err)
newChecksum, err = checksumFromPaths("", paths)
require.NoError(t, err)
require.Equal(t, newChecksum, fileContent)
}
29 changes: 8 additions & 21 deletions starport/services/chain/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/http"
"os"
"os/exec"
"os/signal"
"path"
"path/filepath"

Expand Down Expand Up @@ -198,26 +197,6 @@ If the new code is no longer compatible with the saved state, you can reset the
return c.watchAppBackend(ctx)
})

// save the source checksum on exit
// this goroutine is not in the waiting group to not block the program in case the blockchain start fails
go func() {
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
<-interrupt

fmt.Fprintf(c.stdLog(logStarport).out, "\nExiting...\n")
saveDir, err := c.chainSavePath()
if err != nil {
fmt.Fprintf(c.stdLog(logStarport).err, "Failed to save source checksum:%s \n", err.Error())
}
if err := dirchange.SaveDirChecksum(c.app.Path, appBackendSourceWatchPaths, saveDir, sourceChecksum); err != nil {
fmt.Fprintf(c.stdLog(logStarport).err, "Failed to save source checksum:%s \n", err.Error())
}
if err := dirchange.SaveDirChecksum(c.app.Path, appBackendConfigWatchPaths, saveDir, configChecksum); err != nil {
fmt.Fprintf(c.stdLog(logStarport).err, "Failed to save config checksum:%s \n", err.Error())
}
}()

return g.Wait()
}

Expand Down Expand Up @@ -381,6 +360,14 @@ func (c *Chain) serve(ctx context.Context, forceReset bool) error {
fmt.Fprintln(c.stdLog(logStarport).out, "▶️ Restarting existing app...")
}

// save source and config checksum
if err := dirchange.SaveDirChecksum(c.app.Path, appBackendConfigWatchPaths, saveDir, configChecksum); err != nil {
return err
}
if err := dirchange.SaveDirChecksum(c.app.Path, appBackendSourceWatchPaths, saveDir, sourceChecksum); err != nil {
return err
}

// start the blockchain
return c.start(ctx, conf)
}
Expand Dow 3A31 n
0