Raised This Month: $12 Target: $400
 3% 

SetFilePermissions not working


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Trum
AlliedModders Donor
Join Date: Jan 2017
Old 08-17-2020 , 15:56   SetFilePermissions not working
Reply With Quote #1

Hello!

I'm trying to set a files permission but I'm unable to, here is a list what I've debugged.

> I've made sure that the path is correct and that the file exist using FileExists()
> I have also made sure that the folder that the files are in have the permission 777
> I've have made sure that I have the correct plugin file on my server, by setting the plugin version and then checking the version in the console with the sm plugins command

But yet I have not succeeded to set the files permission.

Here is my code:
PHP Code:
#include <sourcemod>
#include <cstrike>
#include <sdktools>

#pragma tabsize 0

char g_sFileName[128];

public 
Plugin myinfo =
{
    
name "",
    
author "",
    
description "",
    
version "1.4",
    
url ""
};

public 
void OnPluginStart()
{
    
HookEvent("round_start"Event_RoundStart); 
    
HookEvent("round_end"Event_RoundEnd);
}

public 
Action Event_RoundStart(Event event, const char[] namebool dontBroadcast)
{
    if(
GameRules_GetProp("m_bWarmupPeriod"))
        return 
Plugin_Handled;
    
    
SetFileName(); // Set the file name

    
ServerCommand("tv_record \"%s\""g_sFileName);

    
char file[255];
    
Format(filesizeof(file), "/home/ogp_agent/OGP_User_Files/dev/csgo/%s.dem"g_sFileName);

    
PrintToConsoleAll("[DEBUG] Started recording: %s"file);
    
    return 
Plugin_Handled;
}

public 
Action Event_RoundEnd(Event event, const char[] namebool dontBroadcast)
{
    if(
GameRules_GetProp("m_bWarmupPeriod"))
        return 
Plugin_Handled;

    
ServerCommand("tv_stoprecord");

    
char oldPath[255];
    
Format(oldPathsizeof(oldPath), "/home/ogp_agent/OGP_User_Files/dev/csgo/%s.dem"g_sFileName);

    
PrintToConsoleAll("[DEBUG] Stopped recording: %s"oldPath);

    if(
FileExists(oldPathtrueNULL_STRING))
    {   
        if(
SetFilePermissions(oldPathFPERM_U_READ|FPERM_U_WRITE|FPERM_U_EXEC|FPERM_G_READ|FPERM_G_WRITE|FPERM_G_EXEC|FPERM_O_READ|FPERM_O_WRITE|FPERM_O_EXEC))
            
PrintToConsoleAll("[DEBUG] File permission changed on %s"oldPath);
        else
            
PrintToConsoleAll("[DEBUG] File permission was not set");
    }

    return 
Plugin_Handled;
}

public 
void SetFileName()
{
    
char time[32];
    
char map[32];

    
FormatTime(timesizeof(time), "%Y%m%d_%H-%M-%S"GetTime());
    
GetCurrentMap(mapsizeof(map));

    
Format(g_sFileNamesizeof(g_sFileName), "demos/turf_%s_%s"maptime);

I keep getting the "[DEBUG] File permission was not set" message sent in console. Why isn't the file's permission being set?
Trum is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 08-20-2020 , 10:01   Re: SetFilePermissions not working
Reply With Quote #2

Are you able to change the file permissions of other files? Maybe the demo file is still in use.
I'm not sure if sourcemod's file natives work with absolute paths outside the game directory.
__________________
Peace-Maker is offline
Trum
AlliedModders Donor
Join Date: Jan 2017
Old 08-20-2020 , 18:56   Re: SetFilePermissions not working
Reply With Quote #3

I solved it, it was that the file was outside the game directory.
Trum is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:23.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode