返回对应的lock root path(不依赖对应的config信息)
502414
public static String getLockRoot(Long channelId, Long pipelineId) {
        // 根据channelId , pipelineId构造path
        return MessageFormat.format(ArbitrateConstants.NODE_LOCK_ROOT,
            String.valueOf(channelId),
            String.valueOf(pipelineId));
    }
343726
def _find_proj_root():
    # type: () -> Optional[str]
    
    proj_files = frozenset(('pelconf.py', 'pelconf.yaml'))
    curr = os.getcwd()

    while curr.startswith('/') and len(curr) > 1:
        if proj_files & frozenset(os.listdir(curr)):
            return curr
        else:
            curr = os.path.dirname(curr)

    return None
591817
def _root(path, root):
    '''
    
    '''
    if root:
        return os.path.join(root, os.path.relpath(path, os.path.sep))
    else:
        return path
934665
def make_config_get(conf_path):
    
    project_root = _get_project_root_from_conf_path(conf_path)
    config = load_config_in_dir(project_root)
    return partial(config_get, config)
368306
def get_runconfig(path=None, root=None, db=None):
    

    return load(path, root=root, db=db)
73805
def get_config_load_path(conf_path=None):
    

    if conf_path is None:
        # test ./andes.conf
        if os.path.isfile('andes.conf'):
            conf_path = 'andes.conf'
        # test ~/andes.conf
        home_dir = os.path.expanduser('~')
        if os.path.isfile(os.path.join(home_dir, '.andes', 'andes.conf')):
            conf_path = os.path.join(home_dir, '.andes', 'andes.conf')

    if conf_path is not None:
        logger.debug('Found config file at {}.'.format(conf_path))

    return conf_path
226108
def set_root_path(self, root_path=None, settings_module=None):
        
        if root_path:
            self.root_path = root_path
            return

        if settings_module:
            self.root_path = os.path.dirname(os.path.abspath(settings_module.__file__))
            return

        # try to guess which module import app.py
        import inspect

        caller = inspect.stack()[1]
        caller_module = inspect.getmodule(caller[0])
        assert hasattr(caller_module, '__file__'), 'Caller module %s should have __file__ attr' % caller_module
        self.root_path = os.path.dirname(os.path.abspath(caller_module.__file__))
863599
def unlock_password(name, root=None):
    '''
    
    '''
    pre_info = info(name, root=root)
    if not pre_info['name']:
        return False

    if not pre_info['passwd'].startswith('!'):
        return True

    cmd = ['passwd']

    if root is not None:
        cmd.extend(('-R', root))

    cmd.extend(('-u', name))

    __salt__['cmd.run'](cmd, python_shell=False)
    return not info(name, root=root)['passwd'].startswith('!')
1205940
function coerceRoot(root) {
  var coerced = root.substring().trim();
  var len = coerced.length;
  if (len > 0 && coerced[len - 1] !== '/') {
    coerced = coerced + '/';
  }
  return coerced;
}
553066
def pathconf(path,
             os_name=os.name,
             isdir_fnc=os.path.isdir,
             pathconf_fnc=getattr(os, 'pathconf', None),
             pathconf_names=getattr(os, 'pathconf_names', ())):
    '''
    
    '''

    if pathconf_fnc and pathconf_names:
        return {key: pathconf_fnc(path, key) for key in pathconf_names}
    if os_name == 'nt':
        maxpath = 246 if isdir_fnc(path) else 259  # 260 minus <END>
    else:
        maxpath = 255  # conservative sane default
    return {
        'PC_PATH_MAX': maxpath,
        'PC_NAME_MAX': maxpath - len(path),
        }
104959
def get_conf_path(filename=None):
    """"""
    conf_dir = osp.join(get_home_dir(), '.condamanager')

    if not osp.isdir(conf_dir):
        os.mkdir(conf_dir)

    if filename is None:
        return conf_dir
    else:
        return osp.join(conf_dir, filename)
22562
function isUserLocked(username, path, callback) {
  var key = SyncLock.generateKey(username);
  redis.hget(key, path, function(err, value) {
    if(err) {
      log.error(err, 'Error getting redis lock key %s.', key);
      return callback(err);
    }

    callback(null, !!value);
  });
}
719703
private void safeSetPathPermission(Path path, OwnerAndPermission ownerAndPermission) {

    try {
      if (ownerAndPermission.getFsPermission() != null) {
        this.fs.setPermission(path, ownerAndPermission.getFsPermission());
      }
    } catch (IOException ioe) {
      log.warn("Failed to set permission for directory " + path, ioe);
    }

    String owner = Strings.isNullOrEmpty(ownerAndPermission.getOwner()) ? null : ownerAndPermission.getOwner();
    String group = Strings.isNullOrEmpty(ownerAndPermission.getGroup()) ? null : ownerAndPermission.getGroup();

    try {
      if (owner != null || group != null) {
        this.fs.setOwner(path, owner, group);
      }
    } catch (IOException ioe) {
      log.warn("Failed to set owner and/or group for path " + path, ioe);
    }
  }
981957
def _lock(self):
    """"""
    lockfile = '{}.lock'.format(self._get_cookie_file())
    safe_mkdir_for(lockfile)
    return OwnerPrintingInterProcessFileLock(lockfile)
754007
def get_lock(self, path):
        
        if self.lockfile:
            return self.lockfile.LockFile(path)
        else:
            with self.job_locks_lock:
                if path not in self.job_locks:
                    lock = threading.Lock()
                    self.job_locks[path] = lock
                else:
                    lock = self.job_locks[path]
            return lock
978043
private Boolean acquireLock(final BooleanMutex mutex) {
        try {
            do {
                if (id == null) {// 构建当前lock的唯一标识
                    long sessionId = getSessionId();
                    String prefix = "x-" + sessionId + "-";
                    // 如果第一次，则创建一个节点
                    String path = zookeeper.create(root + "/" + prefix, data, CreateMode.EPHEMERAL_SEQUENTIAL);
                    int index = path.lastIndexOf("/");
                    id = StringUtils.substring(path, index + 1);
                    idName = new LockNode(id);
                }

                if (id != null) {
                    List<String> names = zookeeper.getChildren(root);
                    if (names.isEmpty()) {
                        logger.warn("lock lost with scene:empty list, id[] and node[]", id, idName);
                        unlock();// 异常情况，退出后重新创建一个
                    } else {
                        // 对节点进行排序
                        SortedSet<LockNode> sortedNames = new TreeSet<LockNode>();
                        for (String name : names) {
                            sortedNames.add(new LockNode(name));
                        }

                        if (sortedNames.contains(idName) == false) {
                            logger.warn("lock lost with scene:not contains ,id[] and node[]", id, idName);
                            unlock();// 异常情况，退出后重新创建一个
                            continue;
                        }

                        // 将第一个节点做为ownerId
                        ownerId = sortedNames.first().getName();
                        if (mutex != null && isOwner()) {
                            mutex.set(true);// 直接更新状态，返回
                            return true;
                        } else if (mutex == null) {
                            return isOwner();
                        }

                        SortedSet<LockNode> lessThanMe = sortedNames.headSet(idName);
                        if (!lessThanMe.isEmpty()) {
                            // 关注一下排队在自己之前的最近的一个节点
                            LockNode lastChildName = lessThanMe.last();
                            lastChildId = lastChildName.getName();
                            // 异步watcher处理
                            IZkConnection connection = zookeeper.getConnection();
                            // zkclient包装的是一个持久化的zk，分布式lock只需要一次性的watcher，需要调用原始的zk链接进行操作
                            ZooKeeper orginZk = ((ZooKeeperx) connection).getZookeeper();
                            Stat stat = orginZk.exists(root + "/" + lastChildId, new AsyncWatcher() {

                                public void asyncProcess(WatchedEvent event) {
                                    if (!mutex.state()) { // 避免重复获取lock
                                        acquireLock(mutex);
                                    } else {
                                        logger.warn("locked successful.");
                                    }
                                }

                            });

                            if (stat == null) {
                                acquireLock(mutex);// 如果节点不存在，需要自己重新触发一下，watcher不会被挂上去
                            }
                        } else {
                            if (isOwner()) {
                                mutex.set(true);
                            } else {
                                logger.warn("lock lost with scene:no less ,id[] and node[]", id, idName);
                                unlock();// 可能自己的节点已超时挂了，所以id和ownerId不相同
                            }
                        }
                    }
                }
            } while (id == null);
        } catch (KeeperException e) {
            exception = e;
            if (mutex != null) {
                mutex.set(true);
            }
        } catch (InterruptedException e) {
            interrupt = e;
            if (mutex != null) {
                mutex.set(true);
            }
        } catch (Throwable e) {
            other = e;
            if (mutex != null) {
                mutex.set(true);
            }
        }

        if (isOwner() && mutex != null) {
            mutex.set(true);
        }
        return Boolean.FALSE;
    }
1286009
public void checkLock(Session session, String path, List<String> tokens) throws LockException
   {
      String repoPath = session.getRepository().hashCode() + "/" + session.getWorkspace().getName() + "/" + path;

      String currentToken = nullResourceLocks.get(repoPath);

      if (currentToken == null)
      {
         return;
      }

      if (tokens != null)
      {
         for (String token : tokens)
         {
            if (token.equals(currentToken))
            {
               return;
            }
         }
      }

      throw new LockException("Resource already locked " + repoPath);
   }