func (fs *osFileSystem) RemoveAll(fileOrDir string) (err error) { fs.logger.Debug(fs.logTag, "Remove all %s", fileOrDir) err = fsWrapper.RemoveAll(fileOrDir) return }
It("HomeDir returns an error if 'username' is not the current user", func() { if !Windows { Skip("Windows only test") } osFs := createOsFs() _, err := osFs.HomeDir("Non-Existent User Name 1234") Expect(err).To(HaveOccurred()) }) It("can remove a directory long path", func() { osFs := createOsFs() rootPath, longPath := randLongPath() err := fsWrapper.MkdirAll(longPath, 0755) defer fsWrapper.RemoveAll(rootPath) Expect(err).ToNot(HaveOccurred()) dstFile, err := ioutil.TempFile(`\\?\`+longPath, "") Expect(err).ToNot(HaveOccurred()) dstPath := path.Join(longPath, filepath.Base(dstFile.Name())) defer os.Remove(dstPath) dstFile.Close() fileInfo, err := osFs.Stat(dstPath) Expect(fileInfo).ToNot(BeNil()) Expect(os.IsNotExist(err)).To(BeFalse()) err = osFs.RemoveAll(dstPath) Expect(err).ToNot(HaveOccurred())
var ( LongPath string rootPath string LongDir string osFs FileSystem ) BeforeEach(func() { LongPath = filepath.Join(os.TempDir(), randSeq(LONG_PATH_LENGTH)) rootPath, LongDir = randLongPath() osFs = createOsFs() }) AfterEach(func() { // don't check for error! fs.RemoveAll(rootPath) fs.Remove(LongPath) }) // TODO: make sure we can cleanup before running tests It("the fs package can cleanup long paths and dirs", func() { f, err := fs.Create(LongPath) Expect(err).To(Succeed()) f.Close() Expect(fs.Remove(LongPath)).To(Succeed()) Expect(fs.MkdirAll(LongDir, 0755)).To(Succeed()) Expect(fs.RemoveAll(LongDir)).To(Succeed()) }) It("can create and delete a directory with a long path", func() {
buf.Write(bytes.Repeat([]byte{i}, 4)) buf.WriteRune(filepath.Separator) } } buf.Write([]byte(randSeq(10))) buf.WriteRune(filepath.Separator) return filepath.Clean(buf.String()) } var _ = Describe("OS FileSystem LongPaths", func() { It("remove all long path", func() { osFs := createOsFs() longPath := makeLongPath() err := fsWrapper.MkdirAll(longPath, 0755) defer fsWrapper.RemoveAll(longPath) Expect(err).ToNot(HaveOccurred()) dstFile, err := ioutil.TempFile(`\\?\`+longPath, "") Expect(err).ToNot(HaveOccurred()) dstPath := path.Join(longPath, filepath.Base(dstFile.Name())) defer os.Remove(dstPath) dstFile.Close() fileInfo, err := osFs.Stat(dstPath) Expect(fileInfo).ToNot(BeNil()) Expect(os.IsNotExist(err)).To(BeFalse()) err = osFs.RemoveAll(dstPath) Expect(err).ToNot(HaveOccurred())