|
@@ -156,8 +156,6 @@ func (s *store) Get(nodePath string, recursive, sorted bool) (*Event, error) {
|
|
|
// If the node has already existed, create will fail.
|
|
// If the node has already existed, create will fail.
|
|
|
// If any node on the path is a file, create will fail.
|
|
// If any node on the path is a file, create will fail.
|
|
|
func (s *store) Create(nodePath string, value string, unique bool, expireTime time.Time) (*Event, error) {
|
|
func (s *store) Create(nodePath string, value string, unique bool, expireTime time.Time) (*Event, error) {
|
|
|
- nodePath = path.Clean(path.Join("/", nodePath))
|
|
|
|
|
-
|
|
|
|
|
s.worldLock.Lock()
|
|
s.worldLock.Lock()
|
|
|
defer s.worldLock.Unlock()
|
|
defer s.worldLock.Unlock()
|
|
|
e, err := s.internalCreate(nodePath, value, unique, false, expireTime, Create)
|
|
e, err := s.internalCreate(nodePath, value, unique, false, expireTime, Create)
|
|
@@ -173,8 +171,6 @@ func (s *store) Create(nodePath string, value string, unique bool, expireTime ti
|
|
|
|
|
|
|
|
// Set function creates or replace the Node at nodePath.
|
|
// Set function creates or replace the Node at nodePath.
|
|
|
func (s *store) Set(nodePath string, value string, expireTime time.Time) (*Event, error) {
|
|
func (s *store) Set(nodePath string, value string, expireTime time.Time) (*Event, error) {
|
|
|
- nodePath = path.Clean(path.Join("/", nodePath))
|
|
|
|
|
-
|
|
|
|
|
s.worldLock.Lock()
|
|
s.worldLock.Lock()
|
|
|
defer s.worldLock.Unlock()
|
|
defer s.worldLock.Unlock()
|
|
|
e, err := s.internalCreate(nodePath, value, false, true, expireTime, Set)
|
|
e, err := s.internalCreate(nodePath, value, false, true, expireTime, Set)
|
|
@@ -192,6 +188,10 @@ func (s *store) CompareAndSwap(nodePath string, prevValue string, prevIndex uint
|
|
|
value string, expireTime time.Time) (*Event, error) {
|
|
value string, expireTime time.Time) (*Event, error) {
|
|
|
|
|
|
|
|
nodePath = path.Clean(path.Join("/", nodePath))
|
|
nodePath = path.Clean(path.Join("/", nodePath))
|
|
|
|
|
+ // we do not allow the user to change "/"
|
|
|
|
|
+ if nodePath == "/" {
|
|
|
|
|
+ return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, "/", s.CurrentIndex)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
s.worldLock.Lock()
|
|
s.worldLock.Lock()
|
|
|
defer s.worldLock.Unlock()
|
|
defer s.worldLock.Unlock()
|
|
@@ -238,6 +238,10 @@ func (s *store) CompareAndSwap(nodePath string, prevValue string, prevIndex uint
|
|
|
// If the node is a directory, recursive must be true to delete it.
|
|
// If the node is a directory, recursive must be true to delete it.
|
|
|
func (s *store) Delete(nodePath string, recursive bool) (*Event, error) {
|
|
func (s *store) Delete(nodePath string, recursive bool) (*Event, error) {
|
|
|
nodePath = path.Clean(path.Join("/", nodePath))
|
|
nodePath = path.Clean(path.Join("/", nodePath))
|
|
|
|
|
+ // we do not allow the user to change "/"
|
|
|
|
|
+ if nodePath == "/" {
|
|
|
|
|
+ return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, "/", s.CurrentIndex)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
s.worldLock.Lock()
|
|
s.worldLock.Lock()
|
|
|
defer s.worldLock.Unlock()
|
|
defer s.worldLock.Unlock()
|
|
@@ -334,13 +338,17 @@ func (s *store) walk(nodePath string, walkFunc func(prev *Node, component string
|
|
|
// If the node is a file, the value and the ttl can be updated.
|
|
// If the node is a file, the value and the ttl can be updated.
|
|
|
// If the node is a directory, only the ttl can be updated.
|
|
// If the node is a directory, only the ttl can be updated.
|
|
|
func (s *store) Update(nodePath string, newValue string, expireTime time.Time) (*Event, error) {
|
|
func (s *store) Update(nodePath string, newValue string, expireTime time.Time) (*Event, error) {
|
|
|
|
|
+ nodePath = path.Clean(path.Join("/", nodePath))
|
|
|
|
|
+ // we do not allow the user to change "/"
|
|
|
|
|
+ if nodePath == "/" {
|
|
|
|
|
+ return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, "/", s.CurrentIndex)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
s.worldLock.Lock()
|
|
s.worldLock.Lock()
|
|
|
defer s.worldLock.Unlock()
|
|
defer s.worldLock.Unlock()
|
|
|
|
|
|
|
|
currIndex, nextIndex := s.CurrentIndex, s.CurrentIndex+1
|
|
currIndex, nextIndex := s.CurrentIndex, s.CurrentIndex+1
|
|
|
|
|
|
|
|
- nodePath = path.Clean(path.Join("/", nodePath))
|
|
|
|
|
-
|
|
|
|
|
n, err := s.internalGet(nodePath)
|
|
n, err := s.internalGet(nodePath)
|
|
|
|
|
|
|
|
if err != nil { // if the node does not exist, return error
|
|
if err != nil { // if the node does not exist, return error
|
|
@@ -390,6 +398,11 @@ func (s *store) internalCreate(nodePath string, value string, unique bool, repla
|
|
|
|
|
|
|
|
nodePath = path.Clean(path.Join("/", nodePath))
|
|
nodePath = path.Clean(path.Join("/", nodePath))
|
|
|
|
|
|
|
|
|
|
+ // we do not allow the user to change "/"
|
|
|
|
|
+ if nodePath == "/" {
|
|
|
|
|
+ return nil, etcdErr.NewError(etcdErr.EcodeRootROnly, "/", currIndex)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// Assume expire times that are way in the past are not valid.
|
|
// Assume expire times that are way in the past are not valid.
|
|
|
// This can occur when the time is serialized to JSON and read back in.
|
|
// This can occur when the time is serialized to JSON and read back in.
|
|
|
if expireTime.Before(minExpireTime) {
|
|
if expireTime.Before(minExpireTime) {
|