Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-cli
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Operations
Operations
Metrics
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-cli
Commits
2a5a79d3
Commit
2a5a79d3
authored
Aug 31, 2018
by
Cristian Maglie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go-paths-helper API change
parent
65154185
Changes
19
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
80 additions
and
66 deletions
+80
-66
Gopkg.lock
Gopkg.lock
+4
-4
arduino/cores/cores.go
arduino/cores/cores.go
+1
-1
arduino/cores/packagemanager/loader.go
arduino/cores/packagemanager/loader.go
+8
-10
arduino/libraries/librariesmanager/install.go
arduino/libraries/librariesmanager/install.go
+1
-1
arduino/libraries/loader.go
arduino/libraries/loader.go
+3
-3
arduino/resources/helpers.go
arduino/resources/helpers.go
+1
-6
arduino/resources/install.go
arduino/resources/install.go
+2
-2
configs/hardware_directories.go
configs/hardware_directories.go
+2
-4
configs/preferences_txt_serializer.go
configs/preferences_txt_serializer.go
+1
-1
vendor/github.com/arduino/arduino-builder/container_find_includes.go
...ub.com/arduino/arduino-builder/container_find_includes.go
+1
-1
vendor/github.com/arduino/arduino-builder/fail_if_imported_library_is_wrong.go
...uino/arduino-builder/fail_if_imported_library_is_wrong.go
+1
-1
vendor/github.com/arduino/arduino-builder/load_previous_build_options.go
...om/arduino/arduino-builder/load_previous_build_options.go
+2
-7
vendor/github.com/arduino/arduino-builder/merge_sketch_with_bootloader.go
...m/arduino/arduino-builder/merge_sketch_with_bootloader.go
+3
-3
vendor/github.com/arduino/arduino-builder/phases/sketch_builder.go
...thub.com/arduino/arduino-builder/phases/sketch_builder.go
+1
-1
vendor/github.com/arduino/arduino-builder/platform_keys_rewrite_loader.go
...m/arduino/arduino-builder/platform_keys_rewrite_loader.go
+1
-1
vendor/github.com/arduino/arduino-builder/unused_compiled_libraries_remover.go
...uino/arduino-builder/unused_compiled_libraries_remover.go
+2
-2
vendor/github.com/arduino/go-paths-helper/README.md
vendor/github.com/arduino/go-paths-helper/README.md
+1
-1
vendor/github.com/arduino/go-paths-helper/list.go
vendor/github.com/arduino/go-paths-helper/list.go
+2
-2
vendor/github.com/arduino/go-paths-helper/paths.go
vendor/github.com/arduino/go-paths-helper/paths.go
+43
-15
No files found.
Gopkg.lock
View file @
2a5a79d3
...
...
@@ -3,7 +3,7 @@
[[projects]]
branch = "cli-inception"
digest = "1:
6eba8131d991db4e2af3227360fd74387f558ff7f6087dc4370074e63ade1a71
"
digest = "1:
3238cb26ae6f3f359a578afdf2c830d8110bea3a1fc10e620724db99e672d174
"
name = "github.com/arduino/arduino-builder"
packages = [
".",
...
...
@@ -17,7 +17,7 @@
"utils",
]
pruneopts = "UT"
revision = "f9
9ab5a8093d682b710b9eebf67304aa829f5b15
"
revision = "f9
276b5710cc5f2300d5e0bb352ed0771864b876
"
source = "github.com/arduino/arduino-builder"
[[projects]]
...
...
@@ -30,11 +30,11 @@
[[projects]]
branch = "master"
digest = "1:
6e187ec48f872c78e3546a99d39d0a770771dc34c27b78a15f08fbf7175b39f5
"
digest = "1:
5c252a193aaa1c0306a7465d11022653dab30d36c3ab5e1e47bd3d608659f061
"
name = "github.com/arduino/go-paths-helper"
packages = ["."]
pruneopts = "UT"
revision = "
571aca5072f595c081b5ecfb96a465b714533ae5
"
revision = "
44d19052dd968f9ee7c3cc26043b81752794a6dd
"
[[projects]]
branch = "master"
...
...
arduino/cores/cores.go
View file @
2a5a79d3
...
...
@@ -209,7 +209,7 @@ func (release *PlatformRelease) RuntimeProperties() properties.Map {
// present
func
(
release
*
PlatformRelease
)
GetLibrariesDir
()
*
paths
.
Path
{
libDir
:=
release
.
InstallDir
.
Join
(
"libraries"
)
if
isDir
,
_
:=
libDir
.
IsDir
();
isDir
{
if
libDir
.
IsDir
()
{
return
libDir
}
return
nil
...
...
arduino/cores/packagemanager/loader.go
View file @
2a5a79d3
...
...
@@ -64,9 +64,7 @@ func (pm *PackageManager) LoadHardwareFromDirectory(path *paths.Path) error {
}
// TODO: IS THIS CHECK NEEDED? can we ignore and let it fail at next ReadDir?
if
isDir
,
err
:=
path
.
IsDir
();
err
!=
nil
{
return
fmt
.
Errorf
(
"reading %s stat info: %s"
,
path
,
err
)
}
else
if
!
isDir
{
if
!
path
.
IsDir
()
{
return
fmt
.
Errorf
(
"%s is not a directory"
,
path
)
}
...
...
@@ -103,10 +101,10 @@ func (pm *PackageManager) LoadHardwareFromDirectory(path *paths.Path) error {
// in the latter case we just move into "hardware" directory and continue
var
architectureParentPath
*
paths
.
Path
hardwareSubdirPath
:=
packagerPath
.
Join
(
"hardware"
)
// ex: .arduino15/packages/arduino/hardware
if
isDir
,
_
:=
hardwareSubdirPath
.
IsDir
();
isDir
{
if
hardwareSubdirPath
.
IsDir
()
{
// we found the "hardware" directory move down into that
architectureParentPath
=
hardwareSubdirPath
// ex: .arduino15/packages/arduino/
}
else
if
isDir
,
_
:=
packagerPath
.
IsDir
();
isDir
{
}
else
if
packagerPath
.
IsDir
()
{
// we are already at the correct level
architectureParentPath
=
packagerPath
}
else
{
...
...
@@ -122,7 +120,7 @@ func (pm *PackageManager) LoadHardwareFromDirectory(path *paths.Path) error {
// Check if we have tools to load, the directory structure is as follows:
// - PACKAGER/tools/TOOL-NAME/TOOL-VERSION/... (ex: arduino/tools/bossac/1.7.0/...)
toolsSubdirPath
:=
packagerPath
.
Join
(
"tools"
)
if
isDir
,
_
:=
toolsSubdirPath
.
IsDir
();
isDir
{
if
toolsSubdirPath
.
IsDir
()
{
pm
.
Log
.
Infof
(
"Checking existence of 'tools' path: %s"
,
toolsSubdirPath
)
if
err
:=
pm
.
loadToolsFromPackage
(
targetPackage
,
toolsSubdirPath
);
err
!=
nil
{
return
fmt
.
Errorf
(
"loading tools from %s: %s"
,
toolsSubdirPath
,
err
)
...
...
@@ -150,7 +148,7 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir
continue
}
platformPath
:=
packageDir
.
Join
(
architecure
)
if
isDir
,
_
:=
platformPath
.
IsDir
();
!
isDir
{
if
!
platformPath
.
IsDir
()
{
continue
}
...
...
@@ -159,7 +157,7 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir
// - ARCHITECTURE/VERSION/boards.txt
// We identify them by checking where is the bords.txt file
possibleBoardTxtPath
:=
platformPath
.
Join
(
"boards.txt"
)
if
exist
,
err
:=
possibleBoardTxtPath
.
Exist
();
err
!=
nil
{
if
exist
,
err
:=
possibleBoardTxtPath
.
Exist
Check
();
err
!=
nil
{
return
fmt
.
Errorf
(
"looking for boards.txt in %s: %s"
,
possibleBoardTxtPath
,
err
)
...
...
@@ -169,7 +167,7 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir
// this is an unversioned Platform
// FIXME: this check is duplicated, find a better way to handle this
if
exist
,
err
:=
platformPath
.
Join
(
"boards.txt"
)
.
Exist
();
err
!=
nil
{
if
exist
,
err
:=
platformPath
.
Join
(
"boards.txt"
)
.
Exist
Check
();
err
!=
nil
{
return
fmt
.
Errorf
(
"opening boards.txt: %s"
,
err
)
}
else
if
!
exist
{
continue
...
...
@@ -198,7 +196,7 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir
versionDirs
.
FilterDirs
()
versionDirs
.
FilterOutHiddenFiles
()
for
_
,
versionDir
:=
range
versionDirs
{
if
exist
,
err
:=
versionDir
.
Join
(
"boards.txt"
)
.
Exist
();
err
!=
nil
{
if
exist
,
err
:=
versionDir
.
Join
(
"boards.txt"
)
.
Exist
Check
();
err
!=
nil
{
return
fmt
.
Errorf
(
"opening boards.txt: %s"
,
err
)
}
else
if
!
exist
{
continue
...
...
arduino/libraries/librariesmanager/install.go
View file @
2a5a79d3
...
...
@@ -50,7 +50,7 @@ func (lm *LibrariesManager) Install(indexLibrary *librariesindex.Release) (*path
libPath
:=
libsDir
.
Join
(
utils
.
SanitizeName
(
indexLibrary
.
Library
.
Name
))
if
replaced
!=
nil
&&
replaced
.
InstallDir
.
EquivalentTo
(
libPath
)
{
formatter
.
Print
(
fmt
.
Sprintf
(
"Replacing %s with %s"
,
replaced
,
indexLibrary
))
}
else
if
isdir
,
_
:=
libPath
.
IsDir
();
isdir
{
}
else
if
libPath
.
IsDir
()
{
return
nil
,
fmt
.
Errorf
(
"destination dir %s already exists, cannot install"
,
libPath
)
}
return
libPath
,
indexLibrary
.
Resource
.
Install
(
lm
.
DownloadsDir
,
libsDir
,
libPath
)
...
...
arduino/libraries/loader.go
View file @
2a5a79d3
...
...
@@ -28,7 +28,7 @@ import (
// Load loads a library from the given LibraryLocation
func
Load
(
libDir
*
paths
.
Path
,
location
LibraryLocation
)
(
*
Library
,
error
)
{
if
exist
,
_
:=
libDir
.
Join
(
"library.properties"
)
.
Exist
();
exist
{
if
libDir
.
Join
(
"library.properties"
)
.
Exist
()
{
return
makeNewLibrary
(
libDir
,
location
)
}
return
makeLegacyLibrary
(
libDir
,
location
)
...
...
@@ -36,7 +36,7 @@ func Load(libDir *paths.Path, location LibraryLocation) (*Library, error) {
func
addUtilityDirectory
(
library
*
Library
)
{
utilitySourcePath
:=
library
.
InstallDir
.
Join
(
"utility"
)
if
isDir
,
_
:=
utilitySourcePath
.
IsDir
();
isDir
{
if
utilitySourcePath
.
IsDir
()
{
library
.
UtilityDir
=
utilitySourcePath
}
}
...
...
@@ -60,7 +60,7 @@ func makeNewLibrary(libraryDir *paths.Path, location LibraryLocation) (*Library,
library
:=
&
Library
{}
library
.
Location
=
location
library
.
InstallDir
=
libraryDir
if
exist
,
_
:=
libraryDir
.
Join
(
"src"
)
.
Exist
();
exist
{
if
libraryDir
.
Join
(
"src"
)
.
Exist
()
{
library
.
Layout
=
RecursiveLayout
library
.
SourceDir
=
libraryDir
.
Join
(
"src"
)
}
else
{
...
...
arduino/resources/helpers.go
View file @
2a5a79d3
...
...
@@ -41,12 +41,7 @@ func (r *DownloadResource) IsCached(downloadDir *paths.Path) (bool, error) {
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"getting archive path: %s"
,
err
)
}
exist
,
err
:=
archivePath
.
Exist
()
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"checking archive existence: %s"
,
err
)
}
return
exist
,
nil
return
archivePath
.
Exist
(),
nil
}
// Download a DownloadResource.
...
...
arduino/resources/install.go
View file @
2a5a79d3
...
...
@@ -76,7 +76,7 @@ func (release *DownloadResource) Install(downloadDir, tempPath, destDir *paths.P
}()
// If the destination dir already exists remove it
if
isdir
,
_
:=
destDir
.
IsDir
();
isdir
{
if
destDir
.
IsDir
()
{
destDir
.
RemoveAll
()
}
...
...
@@ -110,7 +110,7 @@ func findPackageRoot(parent *paths.Path) (*paths.Path, error) {
}
var
root
*
paths
.
Path
for
_
,
file
:=
range
files
{
if
isdir
,
_
:=
file
.
IsDir
();
!
isdir
{
if
!
file
.
IsDir
()
{
continue
}
if
root
==
nil
{
...
...
configs/hardware_directories.go
View file @
2a5a79d3
...
...
@@ -35,13 +35,11 @@ func (config *Configuration) HardwareDirectories() (paths.PathList, error) {
}
}
dir
:=
config
.
PackagesDir
()
if
isdir
,
_
:=
dir
.
IsDir
();
isdir
{
if
dir
:=
config
.
PackagesDir
();
dir
.
IsDir
()
{
res
.
Add
(
dir
)
}
dir
=
config
.
SketchbookDir
.
Join
(
"hardware"
)
if
isdir
,
_
:=
dir
.
IsDir
();
isdir
{
if
dir
:=
config
.
SketchbookDir
.
Join
(
"hardware"
);
dir
.
IsDir
()
{
res
.
Add
(
dir
)
}
...
...
configs/preferences_txt_serializer.go
View file @
2a5a79d3
...
...
@@ -130,7 +130,7 @@ func proxyConfigsFromIDEPrefs(props properties.Map) error {
func
IDEBundledLibrariesDir
()
*
paths
.
Path
{
if
IsBundledInDesktopIDE
()
{
libDir
:=
paths
.
New
(
*
arduinoIDEDirectory
,
"libraries"
)
if
isDir
,
_
:=
libDir
.
IsDir
();
isDir
{
if
libDir
.
IsDir
()
{
return
libDir
}
}
...
...
vendor/github.com/arduino/arduino-builder/container_find_includes.go
View file @
2a5a79d3
...
...
@@ -144,7 +144,7 @@ func (s *ContainerFindIncludes) Run(ctx *types.Context) error {
sourceFilePaths
:=
ctx
.
CollectedSourceFiles
queueSourceFilesFromFolder
(
ctx
,
sourceFilePaths
,
sketch
,
ctx
.
SketchBuildPath
,
false
/* recurse */
)
srcSubfolderPath
:=
ctx
.
SketchBuildPath
.
Join
(
constants
.
SKETCH_FOLDER_SRC
)
if
isDir
,
_
:=
srcSubfolderPath
.
IsDir
();
isDir
{
if
srcSubfolderPath
.
IsDir
()
{
queueSourceFilesFromFolder
(
ctx
,
sourceFilePaths
,
sketch
,
srcSubfolderPath
,
true
/* recurse */
)
}
...
...
vendor/github.com/arduino/arduino-builder/fail_if_imported_library_is_wrong.go
View file @
2a5a79d3
...
...
@@ -47,7 +47,7 @@ func (s *FailIfImportedLibraryIsWrong) Run(ctx *types.Context) error {
for
_
,
library
:=
range
ctx
.
ImportedLibraries
{
if
!
library
.
IsLegacy
{
if
isDir
,
_
:=
library
.
InstallDir
.
Join
(
constants
.
LIBRARY_FOLDER_ARCH
)
.
IsDir
();
isDir
{
if
library
.
InstallDir
.
Join
(
constants
.
LIBRARY_FOLDER_ARCH
)
.
IsDir
()
{
return
i18n
.
ErrorfWithLogger
(
logger
,
constants
.
MSG_ARCH_FOLDER_NOT_SUPPORTED
)
}
for
_
,
propName
:=
range
libraries
.
MandatoryProperties
{
...
...
vendor/github.com/arduino/arduino-builder/load_previous_build_options.go
View file @
2a5a79d3
...
...
@@ -40,12 +40,8 @@ type LoadPreviousBuildOptionsMap struct{}
func
(
s
*
LoadPreviousBuildOptionsMap
)
Run
(
ctx
*
types
.
Context
)
error
{
buildOptionsFile
:=
ctx
.
BuildPath
.
Join
(
constants
.
BUILD_OPTIONS_FILE
)
if
exist
,
err
:=
buildOptionsFile
.
Exist
();
err
==
nil
{
if
!
exist
{
return
nil
}
}
else
{
return
i18n
.
WrapError
(
err
)
if
buildOptionsFile
.
NotExist
()
{
return
nil
}
bytes
,
err
:=
buildOptionsFile
.
ReadFile
()
...
...
@@ -54,6 +50,5 @@ func (s *LoadPreviousBuildOptionsMap) Run(ctx *types.Context) error {
}
ctx
.
BuildOptionsJsonPrevious
=
string
(
bytes
)
return
nil
}
vendor/github.com/arduino/arduino-builder/merge_sketch_with_bootloader.go
View file @
2a5a79d3
...
...
@@ -58,9 +58,9 @@ func (s *MergeSketchWithBootloader) Run(ctx *types.Context) error {
sketchInSubfolder
:=
buildPath
.
Join
(
constants
.
FOLDER_SKETCH
,
sketchFileName
+
".hex"
)
var
builtSketchPath
*
paths
.
Path
if
exist
,
_
:=
sketchInBuildPath
.
Exist
();
exist
{
if
sketchInBuildPath
.
Exist
()
{
builtSketchPath
=
sketchInBuildPath
}
else
if
exist
,
_
:=
sketchInSubfolder
.
Exist
();
exist
{
}
else
if
sketchInSubfolder
.
Exist
()
{
builtSketchPath
=
sketchInSubfolder
}
else
{
return
nil
...
...
@@ -75,7 +75,7 @@ func (s *MergeSketchWithBootloader) Run(ctx *types.Context) error {
bootloader
=
buildProperties
.
ExpandPropsInString
(
bootloader
)
bootloaderPath
:=
buildProperties
.
GetPath
(
constants
.
BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH
)
.
Join
(
constants
.
FOLDER_BOOTLOADERS
,
bootloader
)
if
exist
,
_
:=
bootloaderPath
.
Exist
();
!
exist
{
if
bootloaderPath
.
NotExist
()
{
logger
.
Fprintln
(
os
.
Stdout
,
constants
.
LOG_LEVEL_WARN
,
constants
.
MSG_BOOTLOADER_FILE_MISSING
,
bootloaderPath
)
return
nil
}
...
...
vendor/github.com/arduino/arduino-builder/phases/sketch_builder.go
View file @
2a5a79d3
...
...
@@ -55,7 +55,7 @@ func (s *SketchBuilder) Run(ctx *types.Context) error {
// The "src/" subdirectory of a sketch is compiled recursively
sketchSrcPath
:=
sketchBuildPath
.
Join
(
constants
.
SKETCH_FOLDER_SRC
)
if
isDir
,
_
:=
sketchSrcPath
.
IsDir
();
isDir
{
if
sketchSrcPath
.
IsDir
()
{
srcObjectFiles
,
err
:=
builder_utils
.
CompileFiles
(
ctx
,
sketchSrcPath
,
true
,
sketchSrcPath
,
buildProperties
,
includes
)
if
err
!=
nil
{
return
i18n
.
WrapError
(
err
)
...
...
vendor/github.com/arduino/arduino-builder/platform_keys_rewrite_loader.go
View file @
2a5a79d3
...
...
@@ -89,7 +89,7 @@ func (s *PlatformKeysRewriteLoader) Run(ctx *types.Context) error {
func
findPlatformKeysRewriteTxt
(
folders
paths
.
PathList
)
(
*
paths
.
Path
,
error
)
{
for
_
,
folder
:=
range
folders
{
txtPath
:=
folder
.
Join
(
constants
.
FILE_PLATFORM_KEYS_REWRITE_TXT
)
if
exist
,
err
:=
txtPath
.
Exist
();
exist
{
if
exist
,
err
:=
txtPath
.
Exist
Check
();
exist
{
return
txtPath
,
nil
}
else
if
err
!=
nil
{
return
nil
,
i18n
.
WrapError
(
err
)
...
...
vendor/github.com/arduino/arduino-builder/unused_compiled_libraries_remover.go
View file @
2a5a79d3
...
...
@@ -41,7 +41,7 @@ type UnusedCompiledLibrariesRemover struct{}
func
(
s
*
UnusedCompiledLibrariesRemover
)
Run
(
ctx
*
types
.
Context
)
error
{
librariesBuildPath
:=
ctx
.
LibrariesBuildPath
if
exist
,
_
:=
librariesBuildPath
.
Exist
();
!
exist
{
if
librariesBuildPath
.
NotExist
()
{
return
nil
}
...
...
@@ -52,7 +52,7 @@ func (s *UnusedCompiledLibrariesRemover) Run(ctx *types.Context) error {
return
i18n
.
WrapError
(
err
)
}
for
_
,
file
:=
range
files
{
if
isDir
,
_
:=
file
.
IsDir
();
isDir
{
if
file
.
IsDir
()
{
if
!
utils
.
SliceContains
(
libraryNames
,
file
.
Base
())
{
if
err
:=
file
.
RemoveAll
();
err
!=
nil
{
return
i18n
.
WrapError
(
err
)
...
...
vendor/github.com/arduino/go-paths-helper/README.md
View file @
2a5a79d3
...
...
@@ -37,7 +37,7 @@ using this library can be done this way:
```
go
buildPath
:=
paths
.
New
(
"/path/to/somewhere"
)
srcPath
:=
buildPath
.
Join
(
"src"
)
if
isDir
,
_
:=
srcPath
.
IsDir
();
!
isDir
{
if
!
srcPath
.
IsDir
()
{
scrPath
.
MkdirAll
()
}
```
...
...
vendor/github.com/arduino/go-paths-helper/list.go
View file @
2a5a79d3
...
...
@@ -67,7 +67,7 @@ func (p *PathList) AsStrings() []string {
func
(
p
*
PathList
)
FilterDirs
()
{
res
:=
(
*
p
)[
:
0
]
for
_
,
path
:=
range
*
p
{
if
isDir
,
_
:=
path
.
IsDir
();
isDir
{
if
path
.
IsDir
()
{
res
=
append
(
res
,
path
)
}
}
...
...
@@ -78,7 +78,7 @@ func (p *PathList) FilterDirs() {
func
(
p
*
PathList
)
FilterOutDirs
()
{
res
:=
(
*
p
)[
:
0
]
for
_
,
path
:=
range
*
p
{
if
isDir
,
_
:=
path
.
IsDir
();
isDir
{
if
path
.
IsDir
()
{
res
=
append
(
res
,
path
)
}
}
...
...
vendor/github.com/arduino/go-paths-helper/paths.go
View file @
2a5a79d3
...
...
@@ -229,8 +229,23 @@ func (p *Path) FollowSymLink() error {
return
nil
}
// Exist return true if the path exists
func
(
p
*
Path
)
Exist
()
(
bool
,
error
)
{
// Exist return true if the file denoted by this path exists, false
// in any other case (also in case of error).
func
(
p
*
Path
)
Exist
()
bool
{
exist
,
err
:=
p
.
ExistCheck
()
return
exist
&&
err
==
nil
}
// NotExist return true if the file denoted by this path DO NOT exists, false
// in any other case (also in case of error).
func
(
p
*
Path
)
NotExist
()
bool
{
exist
,
err
:=
p
.
ExistCheck
()
return
!
exist
&&
err
==
nil
}
// ExistCheck return true if the path exists or false if the path doesn't exists.
// In case the check fails false is returned together with the corresponding error.
func
(
p
*
Path
)
ExistCheck
()
(
bool
,
error
)
{
_
,
err
:=
p
.
Stat
()
if
err
==
nil
{
return
true
,
nil
...
...
@@ -241,8 +256,24 @@ func (p *Path) Exist() (bool, error) {
return
false
,
err
}
// IsDir return true if the path exists and is a directory
func
(
p
*
Path
)
IsDir
()
(
bool
,
error
)
{
// IsDir returns true if the path exists and is a directory. In all the other
// cases (and also in case of any error) false is returned.
func
(
p
*
Path
)
IsDir
()
bool
{
isdir
,
err
:=
p
.
IsDirCheck
()
return
isdir
&&
err
==
nil
}
// IsNotDir returns true if the path exists and is NOT a directory. In all the other
// cases (and also in case of any error) false is returned.
func
(
p
*
Path
)
IsNotDir
()
bool
{
isdir
,
err
:=
p
.
IsDirCheck
()
return
!
isdir
&&
err
==
nil
}
// IsDirCheck return true if the path exists and is a directory or false
// if the path exists and is not a directory. In all the other case false and
// the corresponding error is returned.
func
(
p
*
Path
)
IsDirCheck
()
(
bool
,
error
)
{
info
,
err
:=
p
.
Stat
()
if
err
==
nil
{
return
info
.
IsDir
(),
nil
...
...
@@ -315,15 +346,12 @@ func (p *Path) CopyDirTo(dst *Path) error {
src
:=
p
.
Clean
()
dst
=
dst
.
Clean
()
src
Info
,
err
:=
src
.
Stat
()
src
Files
,
err
:=
src
.
ReadDir
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"getting stat infor for %s: %s"
,
src
,
err
)
}
if
!
srcInfo
.
IsDir
()
{
return
fmt
.
Errorf
(
"%s is not a directory"
,
src
)
return
fmt
.
Errorf
(
"error reading source dir %s: %s"
,
src
,
err
)
}
if
exist
,
err
:=
dst
.
Exist
();
exist
{
if
exist
,
err
:=
dst
.
Exist
Check
();
exist
{
return
fmt
.
Errorf
(
"destination %s already exists"
,
dst
)
}
else
if
err
!=
nil
{
return
fmt
.
Errorf
(
"checking if %s exists: %s"
,
dst
,
err
)
...
...
@@ -332,13 +360,13 @@ func (p *Path) CopyDirTo(dst *Path) error {
if
err
:=
dst
.
MkdirAll
();
err
!=
nil
{
return
fmt
.
Errorf
(
"creating destination dir %s: %s"
,
dst
,
err
)
}
if
err
:=
os
.
Chmod
(
dst
.
path
,
srcInfo
.
Mode
());
err
!=
nil
{
return
fmt
.
Errorf
(
"setting permission for dir %s: %s"
,
dst
,
err
)
}
src
Files
,
err
:=
src
.
ReadDir
()
src
Info
,
err
:=
src
.
Stat
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"error reading source dir %s: %s"
,
src
,
err
)
return
fmt
.
Errorf
(
"getting stat info for %s: %s"
,
src
,
err
)
}
if
err
:=
os
.
Chmod
(
dst
.
path
,
srcInfo
.
Mode
());
err
!=
nil
{
return
fmt
.
Errorf
(
"setting permission for dir %s: %s"
,
dst
,
err
)
}
for
_
,
srcPath
:=
range
srcFiles
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment