package file

import (
	"os"
	"path/filepath"
)

func FileDe(userName, filePath string) error {
	currentDir, err := os.Getwd()
	if err != nil {
		return err
	}

	baseDir := filepath.Join(currentDir, "file_library")
	fullFilePath := filepath.Join(baseDir, userName, filePath)

	// 判断文件是否存在
	_, err = os.Stat(fullFilePath)
	if err != nil {
		if os.IsNotExist(err) {
			return os.ErrNotExist
		}
		return err
	}

	err = os.Remove(fullFilePath)
	if err != nil {
		return err
	}

	return nil
}
