Skip to content

Commit

Permalink
Revert "add delete fn"
Browse files Browse the repository at this point in the history
This reverts commit f790544.
  • Loading branch information
pivilartisant committed Aug 8, 2024
1 parent f790544 commit bd467f0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 26 deletions.
24 changes: 0 additions & 24 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ import (
"github.com/massalabs/DeWeb/int/utils"
"github.com/massalabs/DeWeb/int/zipper"
pkgConfig "github.com/massalabs/DeWeb/pkg/config"
"github.com/massalabs/DeWeb/pkg/webmanager"
"github.com/massalabs/DeWeb/pkg/website"
msConfig "github.com/massalabs/station/int/config"
"github.com/massalabs/station/pkg/cache"
"github.com/massalabs/station/pkg/logger"
"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -254,7 +252,6 @@ func viewWebsite(scAddress string, networkInfos *msConfig.NetworkInfos) error {
logger.Infof("Website owner: %s", owner)

// For debugging cache purposes:

// zipFile, err := webmanager.RequestWebsite(scAddress, networkInfos)
zipFile, err := website.Fetch(networkInfos, scAddress)
if err != nil {
Expand Down Expand Up @@ -294,27 +291,6 @@ func deleteWebsite(siteAddress string, config *yamlConfig.Config) error {

logger.Infof("Website %s deleted with operation ID: %s", siteAddress, *operationID)

err = deleteFromCache(siteAddress)
if err != nil {
return fmt.Errorf("failed to delete %s from cache: %v", siteAddress, err)
}

logger.Infof("Website %s deleted from cache", siteAddress)

return nil
}

func deleteFromCache(scAddress string) error {
cache := new(cache.Cache)
fileName := fmt.Sprintf("website_%s.zip", scAddress)

if cache.IsPresent(fileName) {
err := os.Remove(webmanager.CacheDir + fileName)
if err != nil {
return fmt.Errorf("failed to delete from cache: %v", err)
}
}

return nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/webmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/massalabs/station/pkg/logger"
)

const CacheDir = "./websitesCache/"
const cacheDir = "./websitesCache/"

// getWebsiteResource fetches a resource from a website and returns its content.
func GetWebsiteResource(network *msConfig.NetworkInfos, websiteAddress, resourceName string) ([]byte, bool, error) {
Expand Down Expand Up @@ -100,7 +100,7 @@ func fetchAndCache(networkInfo *msConfig.NetworkInfos, scAddress string, cache *

// Compares the last updated timestamp to the file's last modified timestamp.
func isFileOutdated(fileName string, lastUpdated time.Time) (bool, error) {
fi, err := os.Stat(CacheDir + fileName)
fi, err := os.Stat(cacheDir + fileName)
if err != nil {
return false, fmt.Errorf("failed to get file info: %w", err)
}
Expand Down

0 comments on commit bd467f0

Please sign in to comment.