Example #1
0
        // CreateDirectory(buffer<bytes<0x301>, 0x19, 0x301> path)
        public long CreateDirectory(ServiceCtx context)
        {
            string name = ReadUtf8String(context);

            if (name == null)
            {
                return(MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist));
            }

            if (_provider.DirectoryExists(name))
            {
                return(MakeError(ErrorModule.Fs, FsErr.PathAlreadyExists));
            }

            if (IsPathAlreadyInUse(name))
            {
                return(MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse));
            }

            try
            {
                _provider.CreateDirectory(name);
            }
            catch (DirectoryNotFoundException)
            {
                return(MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist));
            }
            catch (UnauthorizedAccessException)
            {
                Logger.PrintError(LogClass.ServiceFs, $"Unable to access {name}");

                throw;
            }

            return(0);
        }