Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Olexandr Shalakhin
cloud
Commits
368b3a6f
Commit
368b3a6f
authored
11 years ago
by
Olexandr Shalakhin
Browse files
Options
Downloads
Patches
Plain Diff
Issue #7 - implemented basic support for .cloudignore
parent
6a68c6af
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cli.go
+74
-7
74 additions, 7 deletions
cli.go
main.go
+3
-0
3 additions, 0 deletions
main.go
with
77 additions
and
7 deletions
cli.go
+
74
−
7
View file @
368b3a6f
package
main
import
(
"bufio"
"encoding/json"
"errors"
"fmt"
...
...
@@ -11,6 +12,8 @@ import (
"os"
"os/user"
"path"
"path/filepath"
"regexp"
)
const
(
...
...
@@ -22,6 +25,30 @@ const (
CLOUDIGNORE
=
".cloudignore"
)
var
(
ignorelist
=
GetIgnoreList
()
)
// GetIgnoreList returns pattern to ignore paths based on .cloudignore
func
GetIgnoreList
()
[]
string
{
f
,
err
:=
os
.
Open
(
CLOUDIGNORE
)
if
err
!=
nil
{
return
[]
string
{
"a^"
}
}
str
:=
[]
string
{}
scanner
:=
bufio
.
NewScanner
(
f
)
for
scanner
.
Scan
()
{
text
:=
scanner
.
Text
()
if
text
[
0
:
2
]
!=
"//"
{
str
=
append
(
str
,
text
)
}
}
if
err
:=
scanner
.
Err
();
err
!=
nil
{
panic
(
err
)
}
return
str
}
// GetCore returns parsed .cloudcore struct
func
GetCore
()
(
storage
.
Core
,
error
)
{
core
:=
storage
.
Core
{}
...
...
@@ -96,8 +123,8 @@ func IsExists(filename string) bool {
return
true
}
// Create
c
onfig
func
Create
(
filename
string
,
v
interface
{})
error
{
// Create
C
onfig
with filename and defined structure
func
Create
Config
(
filename
string
,
v
interface
{})
error
{
template
,
err
:=
json
.
MarshalIndent
(
v
,
""
,
" "
)
if
err
!=
nil
{
panic
(
err
)
...
...
@@ -127,7 +154,7 @@ func initConfigs() {
},
},
}
if
err
:=
Create
(
cloudcorepath
,
core
);
err
!=
nil
{
if
err
:=
Create
Config
(
cloudcorepath
,
core
);
err
!=
nil
{
panic
(
err
)
}
fmt
.
Println
(
"Initializing file:
\t
"
,
cloudcorepath
)
...
...
@@ -142,12 +169,18 @@ func initConfigs() {
},
},
}
if
err
:=
Create
(
CLOUD
,
cloud
);
err
!=
nil
{
if
err
:=
Create
Config
(
CLOUD
,
cloud
);
err
!=
nil
{
panic
(
err
)
}
fmt
.
Println
(
"Initializing file:
\t
"
,
CLOUD
)
}
// TODO cloudignore
// cloudignore
if
ok
:=
IsExists
(
CLOUDIGNORE
);
!
ok
{
if
err
=
ioutil
.
WriteFile
(
CLOUDIGNORE
,
[]
byte
(
"// Put here what to ignore. Syntax like .gitignore
\n
.cloud
\n
.cloudignore
\n
"
),
0644
);
err
!=
nil
{
panic
(
err
)
}
fmt
.
Println
(
"Initializing file:
\t
"
,
CLOUDIGNORE
)
}
}
// Sync folder with defined container name string (default is the first container in the list in local .cloud)
...
...
@@ -179,7 +212,7 @@ func Sync(name string) {
if
err
!=
nil
{
panic
(
err
)
}
fmt
.
Println
(
"Container found:"
,
c
.
Name
)
fmt
.
Println
(
"Container found:
\t
"
,
c
.
Name
)
if
err
!=
nil
{
panic
(
err
)
}
...
...
@@ -194,6 +227,40 @@ func Sync(name string) {
panic
(
err
)
}
fmt
.
Println
(
"Authenticated"
)
return
// walk files upload file to the cloud
dir
,
err
:=
os
.
Getwd
()
if
err
!=
nil
{
panic
(
err
)
}
if
err
=
filepath
.
Walk
(
dir
,
func
(
filename
string
,
info
os
.
FileInfo
,
err
error
)
error
{
// upload only files, not directories
if
!
info
.
IsDir
()
{
fp
,
err
:=
filepath
.
Rel
(
dir
,
filename
)
if
err
!=
nil
{
panic
(
err
)
}
if
!
IsIgnored
(
fp
)
{
fmt
.
Println
(
fp
)
}
}
return
nil
});
err
!=
nil
{
panic
(
err
)
}
}
// IsIgnored path or not. Data is taken from .cloudignore
func
IsIgnored
(
filename
string
)
bool
{
// TODO I am sure it can be done in more elegant and efficient way
for
_
,
v
:=
range
ignorelist
{
re
,
err
:=
regexp
.
Compile
(
"^"
+
v
)
if
err
!=
nil
{
panic
(
err
)
}
// if match found file must be ignored
if
re
.
MatchString
(
filename
)
{
return
true
}
}
return
false
}
This diff is collapsed.
Click to expand it.
main.go
+
3
−
0
View file @
368b3a6f
...
...
@@ -16,6 +16,7 @@ const (
COMMANDS
=
"COMMANDS
\n
"
+
"
\t
init
\t
initialize .cloudcore and .cloud files
\n
"
+
"
\t
sync
\t
synchronize folder with the cloud
\n
"
+
"
\t
ignore
\t
ignore particular file with .cloudignore
\n
"
+
"
\t
clear
\t
clear container
\n
"
+
"
\t
help
\t
show this message
\n\n
"
// CONTRIBUTORS shows package author & contributors
...
...
@@ -44,6 +45,8 @@ func main() {
container
=
args
[
1
]
}
Sync
(
container
)
case
args
[
0
]
==
"ignore"
:
fmt
.
Println
(
"Nothing here yet..."
)
case
args
[
0
]
==
"clear"
:
fmt
.
Println
(
"Nothing here yet..."
)
case
args
[
0
]
==
"help"
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment