Skip to content

os: RemoveAll hangs on a path longer than 260 characters on Windows versions before Windows 10 1607 #36375

Closed
@bsamek

Description

@bsamek

On Go 1.13.5 on Windows 2008 R2, running os.RemoveAll on a directory that contains a path longer than 260 characters hangs.

In the following repro, the directory is created, and then the program hangs on os.RemoveAll.

package main

import (
	"log"
	"os"
	"path/filepath"
)

func main() {
	// make a long path
	a := ""
	b := ""
	for i := 0; i < 150; i++ {
		a += "a"
		b += "b"
	}
	wd, err := os.Getwd()
	if err != nil {
		log.Fatal(err)
	}
	err = os.MkdirAll(filepath.Join(wd, "foo", "bar", a, b), 0755)
	if err != nil {
		log.Fatal(err)
	}

	// remove the root of the long path
	err = os.RemoveAll("foo")
	if err != nil {
		log.Fatal(err)
	}
}

Activity

ALTree

ALTree commented on Jan 3, 2020

@ALTree
Member

Previously: #3358

changed the title [-]os.RemoveAll hangs on a path longer than 260 characters on Windows[/-] [+]os: RemoveAll hangs on a path longer than 260 characters on Windows[/+] on Jan 3, 2020
added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on Jan 3, 2020
added this to the Go1.15 milestone on Jan 3, 2020
networkimprov

networkimprov commented on Jan 4, 2020

@networkimprov
alexbrainman

alexbrainman commented on Jan 4, 2020

@alexbrainman
Member

@bsamek I can reproduce it here, thank you very much.

The problem is that

os.RemoveAll("foo")

calls

os.Remove(`foo\bar\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb`)

which calls

syscall.RemoveDirectory(`foo\bar\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb`)

which fails, because syscalls don't allow for relative path to be longer than 256 chars. But syscall.RemoveDirectory should succeeds, because directory exists and can be deleted.

Path is converted with os.fixLongPath in os.Remove, but os.fixLongPath does not handle relative path, and returns them as is.

Alex

networkimprov

networkimprov commented on Jan 4, 2020

@networkimprov

Could os.RemoveAll() construct an absolute path and pass that to os.Remove() ?

gopherbot

gopherbot commented on Jan 12, 2020

@gopherbot
Contributor

Change https://golang.org/cl/214437 mentions this issue: os: handle long path in RemoveAll for windows

networkimprov

networkimprov commented on Jan 13, 2020

@networkimprov

I don't think that fix is correct...

gopherbot

gopherbot commented on Jan 13, 2020

@gopherbot
Contributor

Change https://golang.org/cl/214598 mentions this issue: os: actually remove long path in TestRemoveAll

gopherbot

gopherbot commented on Jan 13, 2020

@gopherbot
Contributor

Change https://golang.org/cl/214601 mentions this issue: Revert "os: handle long path in RemoveAll for windows"

ianlancetaylor

ianlancetaylor commented on Jan 13, 2020

@ianlancetaylor
Contributor

Patch was reverted, so reopening issue.

63 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsFixThe path to resolution is known, but the work has not been done.OS-Windowshelp wanted

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @zx2c4@TBBle@networkimprov@bsamek@dmitshur

        Issue actions

          os: RemoveAll hangs on a path longer than 260 characters on Windows versions before Windows 10 1607 · Issue #36375 · golang/go