Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenWrt 等使用 tmpfs 的嵌入式设备上传大文件时会导致 /tmp 空间爆满 #519

Closed
ihotte opened this issue Feb 10, 2022 · 3 comments

Comments

@ihotte
Copy link

ihotte commented Feb 10, 2022

Alist Version / Alist 版本

所有

Describe the bug / 问题描述

无法自定义临时目录位置,OpenWrt 等使用 tmpfs 的嵌入式设备上传大文件时会导致 /tmp 空间爆满。

Reproduction / 复现链接

No response

日志 / Logs

No response

@xhofe
Copy link
Member

xhofe commented Feb 11, 2022

我看了一下golang的源码:

// https://github.com/golang/go/blob/e50f0f372b07149e9cf16b8fec80d2d72efe2a87/src/mime/multipart/formdata.go#L93
		if n > maxMemory {
			// too big, write to disk and flush buffer
			file, err := os.CreateTemp("", "multipart-")
			if err != nil {
				return nil, err
			}
// https://github.com/golang/go/blob/e50f0f372b07149e9cf16b8fec80d2d72efe2a87/src/os/tempfile.go#L30
func CreateTemp(dir, pattern string) (*File, error) {
	if dir == "" {
		dir = TempDir()
	}

// https://github.com/golang/go/blob/e50f0f372b07149e9cf16b8fec80d2d72efe2a87/src/os/file.go#L380
// TempDir returns the default directory to use for temporary files.
//
// On Unix systems, it returns $TMPDIR if non-empty, else /tmp.
// On Windows, it uses GetTempPath, returning the first non-empty
// value from %TMP%, %TEMP%, %USERPROFILE%, or the Windows directory.
// On Plan 9, it returns /tmp.
//
// The directory is neither guaranteed to exist nor have accessible
// permissions.
func TempDir() string {
	return tempDir()
}

它默认使用os.TempDir()目录,且未提供修改的接口,在unix系统中,你可以使用$TMPDIR环境变量来覆盖它。

@ihotte
Copy link
Author

ihotte commented Feb 11, 2022

软件 data/temp 目录是干啥的?不知能否自定义路径?现在OpenWrt 备份配置文件会将temp 目录包含进去

@xhofe
Copy link
Member

xhofe commented Feb 11, 2022

临时文件 有些存储上传时需要计算hash,上传完就会删除。

@xhofe xhofe closed this as completed in 228e6d1 Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants