// New returns a new Query as a javascript object, of nil if parentDir is not a
// valid blobRef.
970408
func New(authToken, parentDir string, limit int,
	updadeSearchSession func(string), triggerRender func()) *js.Object {
	parentDirbr, ok := blob.Parse(parentDir)
	if !ok {
		dom.GetWindow().Alert(fmt.Sprintf("invalid parentDir blobRef: %q", parentDir))
		return nil
	}
	return js.MakeWrapper(&Query{
		ParentDir:           parentDirbr,
		AuthToken:           authToken,
		UpdateSearchSession: updadeSearchSession,
		TriggerRender:       triggerRender,
		Limit:               limit,
	})
}
291289
func New(paths ...string) *Backend {
	backend := &Backend{}

	var files []string
	for _, p := range paths {
		if file, err := os.Open(p); err == nil {
			defer file.Close()
			if fileInfo, err := file.Stat(); err == nil {
				if fileInfo.IsDir() {
					yamlFiles, _ := filepath.Glob(filepath.Join(p, "*.yaml"))
					files = append(files, yamlFiles...)

					ymlFiles, _ := filepath.Glob(filepath.Join(p, "*.yml"))
					files = append(files, ymlFiles...)
				} else if fileInfo.Mode().IsRegular() {
					files = append(files, p)
				}
			}
		}
	}
	for _, file := range files {
		if content, err := ioutil.ReadFile(file); err == nil {
			backend.contents = append(backend.contents, content)
		}
	}
	return backend
}
1256222
func New(o *data.Operation, i data.Input, x interface{}) (*Request, error) {
	input := reflect.ValueOf(i)
	if input.IsValid() && input.Elem().IsValid() {
		err := i.Validate()
		if err != nil {
			return nil, err
		}
	}
	output := reflect.ValueOf(x)

	return &Request{
		Operation: o,
		Input:     &input,
		Output:    &output,
	}, nil
}
206319
func New(exec utilexec.Interface, dbus utildbus.Interface, protocol Protocol) Interface {
	return newInternal(exec, dbus, protocol, "")
}
278548
func New() Store {
	s := Store{m: make(map[string]KVPair)}
	s.FuncMap = map[string]interface{}{
		"exists": s.Exists,
		"ls":     s.List,
		"lsdir":  s.ListDir,
		"get":    s.Get,
		"gets":   s.GetAll,
		"getv":   s.GetValue,
		"getvs":  s.GetAllValues,
	}
	return s
}
1270942
func New(dataDir string, optionalParameters ...DBConfiguration) (ret *CyclePDB, err error) {
	ret = &CyclePDB{
		blobs:               &syncblobs{dbs: make([]*blob, 0)},
		dataDir:             dataDir,
		diskTimeOut:         time.Second,
		bucketTimesIn:       []byte("data"),
		metaBucket:          []byte("m"),
		minNumOldBuckets:    2,
		maxBatchSize:        1000,
		readMovementBacklog: 10000,
		initdb:              true,
	}

	for i, config := range optionalParameters {
		if err = config(ret); err != nil {
			return nil, errors.Annotatef(err, "Cannot execute config parameter %d", i)
		}
	}

	if err = ret.blobs.init(ret); err != nil {
		return nil, errors.Annotatef(err, "Cannot locate or open boltdbs at %s", dataDir)
	}

	if ret.initdb {
		err = ret.init()
	}
	if err == nil {
		ret.wg.Add(1)
		ret.readMovements = make(chan readToLocation, ret.readMovementBacklog)
		go ret.readMovementLoop()
	}
	return ret, err
}
866190
func New(authToken string, expr string,
	callback func(searchResults string),
	cleanup func()) *js.Object {
	if err := checkZoomExpr(expr); err != nil {
		dom.GetWindow().Alert(fmt.Sprintf("%v", err))
		return nil
	}
	expr = ShiftZoomPredicate(expr)
	return js.MakeWrapper(&Query{
		AuthToken: authToken,
		Expr:      expr,
		Callback:  callback,
		Cleanup:   cleanup,
		Limit:     50,
	})
}
1102716
func NewQuery(data interface{}) *JsonQuery {
	j := new(JsonQuery)
	j.blob = data.(map[string]interface{})
	return j
}
164764
func New(basePath string) (*bytes.Buffer, error) {
	fi, err := os.Stat(basePath)
	if err != nil {
		return nil, err
	}
	if !fi.IsDir() {
		return nil, fmt.Errorf("path %q is not a directory, which is required for a Firefox profile", basePath)
	}

	buf := new(bytes.Buffer)
	w := zip.NewWriter(buf)
	err = filepath.Walk(basePath, func(filePath string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		if !info.Mode().IsRegular() {
			return nil
		}

		zipFI, err := zip.FileInfoHeader(info)
		if err != nil {
			return err
		}

		// Strip the prefix from the filename (and the trailing directory
		// separator) so that the files are at the root of the zip file.
		zipFI.Name = filePath[len(basePath)+1:]

		// Without this, the Java zip reader throws a java.util.zip.ZipException:
		// "only DEFLATED entries can have EXT descriptor".
		zipFI.Method = zip.Deflate

		w, err := w.CreateHeader(zipFI)
		if err != nil {
			return err
		}

		f, err := os.Open(filePath)
		if err != nil {
			return err
		}
		defer f.Close()

		_, err = io.Copy(w, bufio.NewReader(f))
		return err
	})
	if err != nil {
		return nil, err
	}
	if err := w.Close(); err != nil {
		return nil, err
	}
	return buf, nil
}
896483
func New(client client.APIClient, noResolve bool) *IDResolver {
	return &IDResolver{
		client:    client,
		noResolve: noResolve,
		cache:     make(map[string]string),
	}
}
1217051
func New(maxBytes int64, cache, origin blobserver.Storage) *Storage {
	sto := &Storage{
		origin:        origin,
		cache:         cache,
		lru:           lru.NewUnlocked(0),
		maxCacheBytes: maxBytes,
	}
	return sto
}
77748
func New(db walletdb.DB, params chaincfg.Params) (*FilterStore, error) {
	err := walletdb.Update(db, func(tx walletdb.ReadWriteTx) error {
		// As part of our initial setup, we'll try to create the top
		// level filter bucket. If this already exists, then we can
		// exit early.
		filters, err := tx.CreateTopLevelBucket(filterBucket)
		if err != nil {
			return err
		}

		// If the main bucket doesn't already exist, then we'll need to
		// create the sub-buckets, and also initialize them with the
		// genesis filters.
		genesisBlock := params.GenesisBlock
		genesisHash := params.GenesisHash

		// First we'll create the bucket for the regular filters.
		regFilters, err := filters.CreateBucketIfNotExists(regBucket)
		if err != nil {
			return err
		}

		// With the bucket created, we'll now construct the initial
		// basic genesis filter and store it within the database.
		basicFilter, err := builder.BuildBasicFilter(genesisBlock, nil)
		if err != nil {
			return err
		}

		return putFilter(regFilters, genesisHash, basicFilter)
	})
	if err != nil && err != walletdb.ErrBucketExists {
		return nil, err
	}

	return &FilterStore{
		db: db,
	}, nil
}
53534
func (s *DB) New() *DB {
	clone := s.clone()
	clone.search = nil
	clone.Value = nil
	return clone
}
811996
func New(dir string) *Store {
	if d, err := filepath.EvalSymlinks(dir); err == nil {
		dir = d
	}
	return &Store{
		path: dir,
	}
}
486102
func New(root string) (*DiskStorage, error) {
	// Local disk.
	fi, err := os.Stat(root)
	if os.IsNotExist(err) {
		// As a special case, we auto-created the "packed" directory for subpacked.
		if filepath.Base(root) == "packed" {
			if err := os.Mkdir(root, 0700); err != nil {
				return nil, fmt.Errorf("failed to mkdir packed directory: %v", err)
			}
			fi, err = os.Stat(root)
		} else {
			return nil, fmt.Errorf("Storage root %q doesn't exist", root)
		}
	}
	if err != nil {
		return nil, fmt.Errorf("Failed to stat directory %q: %v", root, err)
	}
	if !fi.IsDir() {
		return nil, fmt.Errorf("storage root %q exists but is not a directory", root)
	}
	fileSto := files.NewStorage(files.OSFS(), root)
	ds := &DiskStorage{
		Storage:    fileSto,
		SubFetcher: fileSto,
		root:       root,
		gen:        local.NewGenerationer(root),
	}
	if _, _, err := ds.StorageGeneration(); err != nil {
		return nil, fmt.Errorf("Error initialization generation for %q: %v", root, err)
	}
	ul, err := osutil.MaxFD()
	if err != nil {
		if err == osutil.ErrNotSupported {
			// Do not set the gate on Windows, since we don't know the ulimit.
			return ds, nil
		}
		return nil, err
	}
	if ul < minFDLimit {
		return nil, fmt.Errorf("the max number of open file descriptors on your system (ulimit -n) is too low. Please fix it with 'ulimit -S -n X' with X being at least %d", recommendedFDLimit)
	}
	// Setting the gate to 80% of the ulimit, to leave a bit of room for other file ops happening in Perkeep.
	// TODO(mpl): make this used and enforced Perkeep-wide. Issue #837.
	fileSto.SetNewFileGate(syncutil.NewGate(int(ul * 80 / 100)))

	err = ds.checkFS()
	if err != nil {
		return nil, err
	}
	return ds, nil
}
342585
func New() (interface{}, error) {
	db := new()
	dbType := dbplugin.NewDatabaseErrorSanitizerMiddleware(db, db.secretValues)

	return dbType, nil
}
435200
func New(path string, fileMode os.FileMode) (*Database, error) {
	if path == "" {
		return nil, errPathMissing
	}

	if fileMode <= 0 {
		fileMode = os.FileMode(DefaultFileMode)
	}

	// create directories if necessary
	if err := os.MkdirAll(filepath.Dir(path), fileMode); err != nil {
		return nil, err
	}

	service, err := bolt.Open(path, fileMode,
		&bolt.Options{Timeout: 20 * time.Second},
	)

	if err != nil {
		return nil, err
	}

	return NewFromDB(service, "sessions")
}