code: func (d *Downloader) ensureDir(dir string) error {
  	dir = normalizePathSeparator(dir)
  	// Fast path: if the cache has the directory, we're done.
  	d.muCache.RLock()
  	cached := d.dirCache.Has(dir)
  	d.muCache.RUnlock()
  	if cached {
  		return nil
  	}
  
  	// Slow path: collect the directory and its parents, then create
  	// them and add them to the cache.
  	d.muCache.Lock()
  	defer d.muCache.Unlock()
  	parents := make([]string, 0, 1)
  	for i := dir; i != "" && !d.dirCache.Has(i); i = filepath.Dir(i) {
  		if i == d.outputDir {
  			break
  		}
  		parents = append(parents, i)
  	}
  	for i := len(parents) - 1; i >= 0; i-- {
  		if err := os.Mkdir(parents[i], os.ModePerm); err != nil && !os.IsExist(err) {
  			return err
  		}
  		d.dirCache.Add(parents[i])
  	}
  	return nil
  }
docs: // ensureDir ensures that the directory dir exists.