func (storage *PublishedStorage) RenameFile(oldName, newName string) error {
	return os.Rename(filepath.Join(storage.rootPath, oldName), filepath.Join(storage.rootPath, newName))
}
RenameFile renames (moves) file
package files
import (
	"fmt"
	"io"
	"os"
	"path/filepath"
	"strings"
	"syscall"
	"github.com/aptly-dev/aptly/aptly"
	"github.com/aptly-dev/aptly/utils"
)
type PublishedStorage struct {
	rootPath     string
	linkMethod   uint
	verifyMethod uint
}
var (
	_ aptly.PublishedStorage           = (*PublishedStorage)(nil)
	_ aptly.FileSystemPublishedStorage = (*PublishedStorage)(nil)
)
const (
	LinkMethodHardLink uint = iota
	LinkMethodSymLink
	LinkMethodCopy
)
const (
	VerificationMethodChecksum uint = iota
	VerificationMethodFileSize
)
func NewPublishedStorage(root string, linkMethod string, verifyMethod string) *PublishedStorage {
	var verifiedLinkMethod uint
	if strings.EqualFold(linkMethod, "copy") {
		verifiedLinkMethod = LinkMethodCopy
	} else if strings.EqualFold(linkMethod, "symlink") {
		verifiedLinkMethod = LinkMethodSymLink
	} else {
		verifiedLinkMethod = LinkMethodHardLink
	}
	var verifiedVerifyMethod uint
	if strings.EqualFold(verifyMethod, "size") {
		verifiedVerifyMethod = VerificationMethodFileSize
	} else {
		verifiedVerifyMethod = VerificationMethodChecksum
	}
	return &PublishedStorage{rootPath: root, linkMethod: verifiedLinkMethod,
		verifyMethod: verifiedVerifyMethod}
}
func (storage *PublishedStorage) PublicPath() string {
	return storage.rootPath
}
func (storage *PublishedStorage) MkDir(path string) error {
	return os.MkdirAll(filepath.Join(storage.rootPath, path), 0777)
}
func (storage *PublishedStorage) PutFile(path string, sourceFilename string) error {
	var (
		source, f *os.File
		err       error
	)
	source, err = os.Open(sourceFilename)
	if err != nil {
		return err
	}
	defer source.Close()
	f, err = os.Create(filepath.Join(storage.rootPath, path))
	if err != nil {
		return err
	}
	defer f.Close()
	_, err = io.Copy(f, source)
	return err
}
func (storage *PublishedStorage) Remove(path string) error {
	if len(path) <= 0 {
		panic("trying to remove empty path")
	}
	filepath := filepath.Join(storage.rootPath, path)
	return os.Remove(filepath)
}
func (storage *PublishedStorage) RemoveDirs(path string, progress aptly.Progress) error {
	if len(path) <= 0 {
		panic("trying to remove the root directory")
	}
	filepath := filepath.Join(storage.rootPath, path)
	if progress != nil {
		progress.Printf("Removing %s...\n", filepath)
	}
	return os.RemoveAll(filepath)
}
func (storage *PublishedStorage) LinkFromPool(publishedDirectory, fileName string, sourcePool aptly.PackagePool,
	sourcePath string, sourceChecksums utils.ChecksumInfo, force bool) error {
	baseName := filepath.Base(fileName)
	poolPath := filepath.Join(storage.rootPath, publishedDirectory, filepath.Dir(fileName))
	err := os.MkdirAll(poolPath, 0777)
	if err != nil {
		return err
	}
	var dstStat, srcStat os.FileInfo
	dstStat, err = os.Stat(filepath.Join(poolPath, baseName))
	if err == nil {
		srcStat, err = sourcePool.Stat(sourcePath)
		if err != nil {
			return err
		}
		if storage.linkMethod == LinkMethodCopy {
			if storage.verifyMethod == VerificationMethodFileSize {
				if srcStat.Size() == dstStat.Size() {
					return nil
				}
			} else {
				var dstMD5 string
				dstMD5, err = utils.MD5ChecksumForFile(filepath.Join(poolPath, baseName))
				if err != nil {
					return err
				}
				if dstMD5 == sourceChecksums.MD5 {
					return nil
				}
			}
		} else {
			srcSys := srcStat.Sys().(*syscall.Stat_t)
			dstSys := dstStat.Sys().(*syscall.Stat_t)
			if srcSys.Ino == dstSys.Ino && srcSys.Dev == dstSys.Dev {
				return nil
			}
		}
		if !force {
			return fmt.Errorf("error linking file to %s: file already exists and is different", filepath.Join(poolPath, baseName))
		}
		err = os.Remove(filepath.Join(poolPath, baseName))
		if err != nil {
			return err
		}
	}
	if storage.linkMethod == LinkMethodCopy {
		var r aptly.ReadSeekerCloser
		r, err = sourcePool.Open(sourcePath)
		if err != nil {
			return err
		}
		var dst *os.File
		dst, err = os.Create(filepath.Join(poolPath, baseName))
		if err != nil {
			r.Close()
			return err
		}
		_, err = io.Copy(dst, r)
		if err != nil {
			r.Close()
			dst.Close()
			return err
		}
		err = r.Close()
		if err != nil {
			dst.Close()
			return err
		}
		err = dst.Close()
	} else if storage.linkMethod == LinkMethodSymLink {
		err = sourcePool.(aptly.LocalPackagePool).Symlink(sourcePath, filepath.Join(poolPath, baseName))
	} else {
		err = sourcePool.(aptly.LocalPackagePool).Link(sourcePath, filepath.Join(poolPath, baseName))
	}
	return err
}
func (storage *PublishedStorage) Filelist(prefix string) ([]string, error) {
	root := filepath.Join(storage.rootPath, prefix)
	result := []string{}
	err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		if !info.IsDir() {
			result = append(result, path[len(root)+1:])
		}
		return nil
	})
	if err != nil && os.IsNotExist(err) {
		return []string{}, nil
	}
	return result, err
}