Example #1
0
func New(context *config.Context, opts *Options) *Commands {
	var r *Remote
	if context != nil {
		r = NewRemoteContext(context)
	}

	stdin, stdout, stderr := os.Stdin, os.Stdout, os.Stderr

	var logger *log.Logger = nil

	if opts == nil {
		logger = log.New(stdin, stdout, stderr)
	} else {
		if opts.Quiet {
			stdout = nil
		}

		if stdout != nil {
			opts.StdoutIsTty = isatty.IsTerminal(stdout.Fd())
		}

		if stdout == nil && opts.Piped {
			panic("piped requires stdout to be non-nil")
		}

		logger = log.New(stdin, stdout, stderr)

		// should always start with /
		opts.Path = path.Clean(path.Join("/", opts.Path))

		if !opts.Force {
			ignoresPath := filepath.Join(context.AbsPath, DriveIgnoreSuffix)
			ignorer, regErr := combineIgnores(ignoresPath)

			if regErr != nil {
				logger.LogErrf("combining ignores from path %s and internally: %v\n", ignoresPath, regErr)
			}

			opts.Ignorer = ignorer
		}
	}

	return &Commands{
		context:       context,
		rem:           r,
		opts:          opts,
		log:           logger,
		mkdirAllCache: expirableCache.New(),
	}
}
Example #2
0
func New(context *config.Context, opts *Options) *Commands {
	var r *Remote
	if context != nil {
		r = NewRemoteContext(context)
	}

	stdin, stdout, stderr := os.Stdin, os.Stdout, os.Stderr

	logger := log.New(stdin, stdout, stderr)

	if opts != nil {
		// should always start with /
		opts.Path = path.Clean(path.Join("/", opts.Path))

		if !opts.Force {
			ignoresPath := filepath.Join(context.AbsPath, DriveIgnoreSuffix)
			ignoreRegexp, regErr := combineIgnores(ignoresPath)

			if regErr != nil {
				logger.LogErrf("combining ignores from path %s and internally: %v\n", ignoresPath, regErr)
			}

			opts.IgnoreRegexp = ignoreRegexp
		}

		opts.StdoutIsTty = isatty.IsTerminal(stdout.Fd())

		if opts.Quiet {
			stdout = nil
		}
	}

	return &Commands{
		context:       context,
		rem:           r,
		opts:          opts,
		log:           logger,
		mkdirAllCache: expirableCache.New(),
	}
}
Example #3
0
	"path/filepath"
	"time"

	expirableCache "github.com/odeke-em/cache"
	watnot "github.com/odeke-em/watnot-dev/src"
)

const (
	Byte  = 1
	KByte = 1024 * Byte
	MByte = 1024 * KByte
)

var MaxThresholdCacheSize = int64(80 * MByte)

var globalDataCache = expirableCache.New()

func relToPublicPath(p string) string {
	return path.Join(".", "public", p)
}

func newExpirableValue30MinuteOffset(data interface{}) *expirableCache.ExpirableValue {
	return expirableCache.NewExpirableValueWithOffset(data, uint64(time.Hour))
}

func retrievePublicResource(subPath string) (data string, err error) {
	key := relToPublicPath(subPath)
	retr, ok := globalDataCache.Get(key)
	if ok {
		value := retr.Value()
		data, ok = value.(string)